I am looking through some React projects, and sometimes see-
export default () => {
But other times I see-
export default class Entry extends React.Component {
.
Is there any difference between the two, viz. does export automatically extend React.Component
? What is the best practice?
The
export default () =>
you see is a React 0.14+ "Functional Component".It's a new more concise syntax for writing React components. Both it and the other syntax are fine.
Basically doing:
Is the same as:
When used inside React component and passed to Render.
The first one is a functional component. However the other code will export a regular class/React component.
For example
Will compile (at least with Babel+webpack) to