Recieve props from parent component and save it in child component state

PHOTO EMBED

Tue Oct 19 2021 23:27:28 GMT+0000 (Coordinated Universal Time)

Saved by @jofinhel #ja #react.js

const SearchBar = (props) => {
  const initialState = [];
  const [options, setoptions] = useState(initialState);

  const nameList = () => {
    props.data.map((i) => setoptions((options) => [...options, i.name.common]));
  };
content_copyCOPY

It will map the data from the prop and add it to options state, using spread operator without mutating the option state