What do you want to save?
Add Code snippet
New code examples
-
Javascript 2022-01-24 19:56:37
Invalid hook call. Hooks can only be called inside of the body of a function component
const Allowance = () => { const [allowances, setAllowances] = useState([]); useEffect(() => { fetch("http://127.0.0.1:8000/allowances") .then(data => { return data.json(); }) .then(data => { ... Add solution -
Javascript 2021-11-12 10:07:35
detect browser back button click react
import { useHistory } from 'react-router-dom' const [ locationKeys, setLocationKeys ] = useState([]) const history = useHistory() useEffect(() => { return history.listen(location => { if (history.action === 'PUSH') { setLocationKeys([... Add solution -
CSS 2021-11-10 14:01:16
How to add object in an array using useState
import React, { useState } from 'react'; function App() { const [items, setItems] = useState([]); // handle click event of the button to add item const addMoreItem = () => { &nb... Add solution -
Javascript 2021-10-12 07:45:06
update component after api res
function MyComponent() { const [error, setError] = useState(null); const [isLoaded, setIsLoaded] = useState(false); const [items, setItems] = useState([]); // Note: the empty deps array [] means // this useEffect will run once // similar to c... Add solution -
Javascript 2021-10-10 01:33:04
functional component how to add to existing array react
const {useState, useCallback} = React; function Example() { const [theArray, setTheArray] = useState([]); const addEntryClick = () => { setTheArray([...theArray, `Entry ${theArray.length}`]); }; return [ <input type=&... Add solution -
Javascript 2021-10-08 17:11:04
Cannot read property 'map' of undefined
function MyComponent() { const [data, setData] = useState([]); const [loading, setLoading] = useState(false); useEffect(() => { setLoading(true); fetch('/api/data') .then((res) => res.json()) .then((data) => { s... Add solution
Best helpers
+5
+5
+5
+5
+5
+5
+5
+5
+5