Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

239
Views
React - How to export a pure stateless component

How can I export a stateless pure dumb component?

If I use class this works:

import React, { Component } from 'react';

export default class Header extends Component {
    render(){
        return <pre>Header</pre>
    }
}

However if I use a pure function I cannot get it to work.

import React, { Component } from 'react';
export default const Header = () => {
    return <pre>Header</pre>
}

Am I missing something basic?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

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

over 4 years ago · Santiago Trujillo Report

0

Just as a side note. You could technically export default without declaring a variable first.

export default () => (
  <pre>Header</pre>
)
over 4 years ago · Santiago Trujillo Report

0

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'
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!