When creating a React component, do I use:
React.createClass
or
export default class MyGriddler extends React.Component
When creating a React component, do I use:
React.createClass
or
export default class MyGriddler extends React.Component
They’re both different ways of creating a component.
If you’re using the old style you can export it as default with:
export default React.createClass(...)
If you’re using the new ES2015 class style you’d use:
export default class MyGriddler extends React.Component
Essentially they’re different ways of doing the same thing. There’s also a third way which looks like this:
export default (props) =>
My advice would be to stick to the last way (functional/stateless), but fall back to the 2nd way (class-based) if you require your component to have internal state.
Here is a medium post that explains the different styles in more detail:
You preempted my next question - excellent - thanks.