Search code examples
javascriptreactjscomponents

In a class extend component a const state = [] would work. how do i do similar in a function app() component?


example:

function App() {

 const state = { Persons: [ { name: 'Stian', age: 32 }, { name: 'Kaja', age: 29 }, { name: 'Oliver', age: 3 }, { name: 'Edwin', age: 1 } ] } };

}

Solution

  • Functional component don't have state, it is a pure function which will return react element.

    check this https://reactjs.org/docs/components-and-props.html#function-and-class-components