S. Schenk S. Schenk - 2 months ago 11x
Javascript Question

How can I Initialize the state when using a stateless function to define my component

I would like to use a stateless function to define my component, but that means I can't use life cycle methods like componentWillMount. So how can I render the component with initial content?

example of the above:

export const Panel = () => (<div></div>)


You can use default props like this:

export const Panel = ({name = 'Default user', age = 'N/A'}) => (
  <div>{name} {age}</div>

More about destructuring objects