score:192
ES6 doesn't allow export default const
. You must declare the constant first then export it:
const Header = () => {
return <pre>Header</pre>
};
export default Header;
This constraint exists to avoid writting export default a, b, c;
that is forbidden: only one variable can be exported as default
score:13
You can also use a function declaration instead of assignment:
export default function Header() {
return <pre>Header</pre>
}
In your example, you already use curly brackets and return
so this is apparently matching with your needs with no compromise.
score:21
you can do it in two ways
const ComponentA = props => {
return <div>{props.header}</div>;
};
export default ComponentA;
2)
export const ComponentA = props => {
return <div>{props.header}</div>;
};
if we use default
to export then we import like this
import ComponentA from '../shared/componentA'
if we don't use default
to export then we import like this
import { ComponentA } from '../shared/componentA'
score:49
Just as a side note. You could technically export default
without declaring a variable first.
export default () => (
<pre>Header</pre>
)
Source: stackoverflow.com
Related Query
- React - How to export a pure stateless component
- How to use children with React Stateless Functional Component in TypeScript?
- How do I export more than one class component with React JS?
- How to export react app to pure static html
- How to export Component for server side rendering in React
- How do I rewrite a react component with decorators as a pure function?
- How to define defaultProps for a stateless react component in typescript?
- Converting stateful React component to stateless functional component: How to implement "componentDidMount" kind of functionality?
- How can I export a React Component as an NPM package to use in separate projects?
- How to handle mouse event in stateless component in React
- React - How to Export Multiple Components on same File, preventing <Unknown/> Component on Dev Tools
- How do export a React component with related "child" components
- How to export React component with props?
- How to correctly export SVGs in a React component library with TypeScript
- How can we write a click handler for a Stateless Function Component in React JS
- How to use ES6 map function in React stateless component
- How to write a React Stateless Functional Component in Typescript?
- How to export React component as npm package? Create-React-App SyntaxError: Unexpected token
- How to pass an external method to a stateless functional component in React
- How to export a react component with 'withRouter' and 'withTranslation'
- How to refer 'this' keyword in React Stateless Component
- How to avoid unnecesary update in a stateless component with a React class-based component as a parent
- How can I export a react material-ui component with 2 styles object? (material-ui V1)
- How to get my withStyles classes to work in my export class component in my React app
- How to use HTML with JS in React app to export component
- How set displayName to a React stateless component with memo?
- Unit testing React stateless component wrapped with withRouter() in Enzyme, how to pass match parameter
- How To Wait To Export React Component Until After A Request. (Shopify App Development)
- How to export a stateless functional component with styles in Reactjs
- How to export react jsx component in an object?
More Query from same tag
- Adding custom css in react template
- I want to change the value of the state with the next values from an array
- Element.createShadowRoot is deprecated and will be removed in M73, around March 2019. Please use Element.attachShadow instead
- Building a referral system using Node/React/MongoDB
- next.js mapStateToProps, mapDispatchToProps and getInitialProps
- Dynamic page title with ReactJS
- React Hook Form - Multiple Rerender
- If setState() is not web api then but asynchrouns, how is it run begind the scenes
- different promise execution on browsers, what happened?
- React hookrouter multiple layouts
- How to render user list in React-Firebase
- Accessing key property of React component
- Unhandled Promise Rejection Warning- React, Jest, and Enzyme
- How to use a third-party API inside next/api?
- componentDidMount not running after calling browserHistory.push("/url")
- Rechartd: Vertical bar chart - set bar thickness
- react js input doesn't allow writing
- Adjust where HTML gets rendered in a map loop
- React + Material-UI | How to create horizontal scroll cards?
- Apollo boost trigger refetch outside of component
- ReactJS : How to properly handle data fetched from food2fork API?
- Router rendering the component on the same page rather than rendering in a new page
- Wordpress Gutenberg React – render variable with HTML
- What's the difference between onClick ={ () => function()} and onClick = {function()}?
- How to wait for Fetch to finish grabbing data before continueing
- Google Not Showing React-Helmet Title And Description
- Not able to set cache-control header for my static resources Express
- Not able to Query hyperlinks from GraphQL on Gatsby JS
- Object literal may only specify known properties, and 'task' does not exist in type 'SetStateAction
- ComponentDidMount causing my server to crash