2

Why would this work:

const PostComponent = ({post}) => (
  <span>
      <div>{post.text}</div>
  </span>
)

export default PostComponent;

And not this:

export default PostComponent = ({post}) => (
  <span>
      <div>{post.text}</div>
  </span>
)

The later says the component is undefined when imported.

2
  • 2
    Because PostComponent is not defined. And you can't define and export at once with default export. export default function({post}) { ... } is possible however. Commented Jan 12, 2017 at 23:13
  • developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… Commented Jan 12, 2017 at 23:22

1 Answer 1

1

dfsq already answered in comments, and just to let you know, this will work

export default ({post}) => (
  <span>
      <div>{post.text}</div>
  </span>
)

but doing this, the component will be anonymous. If you have React devtool installed, you will just see StatelessComponent

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.