skip to Main Content

Javascript – What if setState is used to fetch API?

I was experimenting with react. and used setState as shown below. import {useState} from 'react'; export default function App() { const [state,setState]=useState([]); const fetchApi= async()=>{ return fetch('https://jsonplaceholder.typicode.com/posts') .then(response=>response.json()) .then(data=>{console.log(data); return data}) .catch(err=>console.log(err)) } setState(fetchApi()); return ( <div> </div> ); }…

VIEW QUESTION

Reactjs – How to submit form with react-query

I have following code const useCreateSupplier = (createSupplierCommand: CreateSupplierCommand) => { return useMutation({ mutationFn: () => axiosClient .post("/supplier", { createSupplierCommand }) .then((res: AxiosResponse) => res.data), onSuccess: async () => { await queryClient.invalidateQueries({ queryKey: [queries.get_suppliers], }); }, }); }; const CreateSupplierForm…

VIEW QUESTION
Back To Top
Search