[React] [Question] Naming convention for methods that return jsx partials
See original GitHub issueHi 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:
- Created 7 years ago
- Comments:8 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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@ljharb Thanks for the clarification. In the dateRangePicker.jsx in react-dates repo, there are 2-3 functions like that, like
maybeRenderDayPickerWithPortal
andrenderDayPicker
. 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