fetch api map 1

fetch api map

const GetData = [];
  useEffect(() => {
      .then((res) => res.json())
      .then((data) => {
        setDataState(GetData.map((d) => d.modeName));
  }, []);

Here is what the above code is Doing:
1. We are using the useEffect hook to fetch the data from the API.
2. We are using the push method to push the data into the GetModesData array.
3. We are using the setDataState method to set the data into the dataState array.

Now, let’s add the following code to the render method:

Similar Posts