Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Axios with React Hooks, “traditional” Promise syntax

const useAxiosPost = (url, payload) => {
  const [data, setData] = useState(null);
  const [error, setError] = useState("");
  const [loaded, setLoaded] = useState(false);

  useEffect(() => {
    axios
      .post(url, payload)
      .then((response) => setData(response.data))
      .catch((error) => setError(error.message))
      .finally(() => setLoaded(true));
  }, []);

  return { data, error, loaded };
};
Comment

Axios with React Hooks, “traditional” Promise syntax

const useAxiosPost = (url, payload) => {
  const [data, setData] = useState(null);
  const [error, setError] = useState("");
  const [loaded, setLoaded] = useState(false);

  useEffect(() => {
    axios
      .post(url, payload)
      .then((response) => setData(response.data))
      .catch((error) => setError(error.message))
      .finally(() => setLoaded(true));
  }, []);

  return { data, error, loaded };
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: leaflet core 
Javascript :: searchbar to bottom table datatable 
Javascript :: node js download image from url as buffer 
Javascript :: foreach loop 
Javascript :: merge two binary trees 
Javascript :: fs readfile encoding 
Javascript :: node.js express export routes 
Javascript :: redux actions.js 
Javascript :: how to build with a specific .env file node 
Javascript :: nested template strings js 
Javascript :: How to scan a folder for documents with javascript 
Javascript :: comment faire pour écrire un texte en javascript 
Javascript :: substring in javascript 
Javascript :: fabric js 
Javascript :: omit object javascript 
Javascript :: load js on only specific page wp 
Javascript :: how to add row in angular dynamically 
Javascript :: number vs bigint js 
Javascript :: javascript null Conversion to Number 
Javascript :: node js hello word 
Javascript :: reactjs import electron 
Javascript :: Material-ui aircon icon 
Javascript :: heroku proxy cross origin 
Javascript :: add pdf in react app 
Javascript :: service worker self.clients 
Javascript :: von click 
Javascript :: how to convert string to pascal case in javascript 
Javascript :: html select multiple selected values 
Javascript :: javascript modify href attr 
Javascript :: decapitalize javascript string 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =