hopflink
0
Q:

fetch api map

// This will fetch api.example.com/comments with a header and a body
fetch(`https://api.example.com/comments`, {
  method: 'POST', //This could be any http method
  headers: {
    'Authorization': 'Basic SGVsbG8gdGhlcmUgOikgSGF2ZSBhIGdvb2QgZGF5IQ==',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
	UID: 58,
    Comment: "Fetch is really easy!",
  }),
})
.then((response) => response.json)
.then((newComment) => {
  // Do something magical with your newly posted comment :)
});
2
const GetData = [];
  useEffect(() => {
    fetch(API_URL)
      .then((res) => res.json())
      .then((data) => {
        GetModesData.push(...data);
        setDataState(GetData.map((d) => d.modeName));
      });
  }, []);
1

New to Communities?

Join the community