question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[React] [Question] Naming convention for methods that return jsx partials

See original GitHub issue

Hi All!

I’m not sure this is actually something worth adding to the guidelines so I thought I’d get feedback/ opinions before opening a PR myself…

My suggestion is that methods that render jsx partials be prefixed with ‘render’

For instance:

// bad - suggests data getting
getHeading = () => {
    return <Header>{this.props.header}</Header>
}

// good - returns JSX to be rendered
renderHeading = () => {
    return <Header>{this.props.header}</Header>
}

Of course the method doesn’t actually render any JSX in to the DOM at this stage so it could be argued that render___ is misleading.

Any thoughts on this? If it seems reasonable I can put together a more formal PR this evening - Thanks!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
spencommented, Oct 27, 2016

Thanks for the conversation @Bamieh & @ljharb - learning lots! I’d be more than happy to open some PR’s and help out!

I’m personally not a big fan of the maybeRender__ pattern anyway, it feels ambiguous!
I’m usually in preference to something like: { isSomething && <Component /> } or a ternary

1reaction
Bamiehcommented, Oct 27, 2016

@ljharb Thanks for the clarification. In the dateRangePicker.jsx in react-dates repo, there are 2-3 functions like that, like maybeRenderDayPickerWithPortal and renderDayPicker. But i believe this whole component should be refactored to have the portal in another component/wrapper, since its not the calendar’s concern where its at. Its up to the user to use a portal or not.

https://github.com/airbnb/react-dates/blob/master/src/components/DateRangePicker.jsx#L317

Read more comments on GitHub >

github_iconTop Results From Across the Web

React: What is the naming convention to inform the return ...
As you can see the return type of this function is JSX. Is this the right return type? Or is React element a...
Read more >
JSX In Depth
We recommend naming components with a capital letter. If you do have a component that starts with a lowercase letter, assign it to...
Read more >
Learning Objectives | React.js – Key Concepts
Utilize common naming conventions and code patterns; Describe the relation between components and JSX; Write JSX code and understand why it's used; Write...
Read more >
React with TypeScript Cheatsheet
Since the convention in React is to write one component in one .js or .jsx ... by adding the question mark ? symbol...
Read more >
The React Handbook – Learn React for Beginners
Since create-react-app is a set of common denominator conventions and ... Any variable defined in a function with the same name as a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found