use-effect

Send component new props react - Stuck

谁说胖子不能爱 提交于 2020-05-16 22:00:54
问题 I have been stuck for a few hours now.. I am trying to send a component new props... but It wont get the new ones. Here is what happens. First the user clicks a button on the post component... It fires the function, 'add favorites' and 'addFavs' on the parent component below. These two functions determine if it should add the user to favorites or delete the user from favorites. When the user is added as a favorite, the button they clicked, inside the searchResults component, appears a

Send component new props react - Stuck

倾然丶 夕夏残阳落幕 提交于 2020-05-16 22:00:17
问题 I have been stuck for a few hours now.. I am trying to send a component new props... but It wont get the new ones. Here is what happens. First the user clicks a button on the post component... It fires the function, 'add favorites' and 'addFavs' on the parent component below. These two functions determine if it should add the user to favorites or delete the user from favorites. When the user is added as a favorite, the button they clicked, inside the searchResults component, appears a

Send component new props react - Stuck

孤者浪人 提交于 2020-05-16 22:00:01
问题 I have been stuck for a few hours now.. I am trying to send a component new props... but It wont get the new ones. Here is what happens. First the user clicks a button on the post component... It fires the function, 'add favorites' and 'addFavs' on the parent component below. These two functions determine if it should add the user to favorites or delete the user from favorites. When the user is added as a favorite, the button they clicked, inside the searchResults component, appears a

useEffect React Hook rendering multiple times with async await (submit button)

…衆ロ難τιáo~ 提交于 2020-04-14 07:28:32
问题 I am trying to basically disable the submit button so my api calls only get triggered once/ someone can't click on submit again while the operation is already underway. I converted the runOnSubmit function to an async function and call it directly. I have based this off many other solutions and basically when I do this and debug I can tell that isSubmitting is still set to true and the hook gets called multiple times/ the submitAsync function is called twice. Basically, the setSubmitting gets

Where should I declare functions that are called inside a useEffect() hook?

旧街凉风 提交于 2020-04-13 05:03:07
问题 So I have the following situation when using a useEffect that calls a functions that depends on state. Example: // INSIDE APP COMPONENT const [someState, setSomeState] = React.useState(0); const [someTrigger, setSomeTrigger] = React.useState(false); function someFunction() { return someState + 1; } React.useEffect(() => { const newState = someFunction(); // 'someFunction' IS BEING CALLED HERE setSomeState(newState); },[someTrigger]) QUESTIONS: In this case, should I declare someFunction

In React useEffect does not update after the value has changed from other component

耗尽温柔 提交于 2020-03-16 06:48:07
问题 I am trying to do some kind of online shop for myself and I got a problem. I want to render my shopping cart size in the NavBar component (which is on every page). I created a Cart Items service where I put all my added items, and it also has functions to addItem , removeItem , getCart , getCartSize . When I click on Add/Remove on specific product, I would like to do that the value on NavBar with cart size would be changing depending on the cart size (from getCartSize method). I already tried

values.map is not a function reactjs

≡放荡痞女 提交于 2020-01-16 10:18:19
问题 i am fetchin details from database wanted to display that into the table, but for initial purpose i wanted to just display on browser without table and stuff.. am getting values.map is not a function but i could the see values printed in console here iam using function component export default function SimpleTable() { const [values, setValues] = useState({}); here is the fetch function async function handleTable(){ const res = await fetch("http://localhost:4000/productslist") const data =

values.map is not a function reactjs

我的梦境 提交于 2020-01-16 10:17:12
问题 i am fetchin details from database wanted to display that into the table, but for initial purpose i wanted to just display on browser without table and stuff.. am getting values.map is not a function but i could the see values printed in console here iam using function component export default function SimpleTable() { const [values, setValues] = useState({}); here is the fetch function async function handleTable(){ const res = await fetch("http://localhost:4000/productslist") const data =

Reactjs why useEffect sometimes runs on every mount/render instead of just first

烈酒焚心 提交于 2020-01-16 09:06:09
问题 I have a useEffect in my Routes in App.js <Switch> <Route exact path={['/en', '/fr']} component={HomePage} /> <Route path={['/en/*', '/fr/*']}> <Route path="/:lang/*" component={DefaultLanguage} /> in the same file(App.js) we have the component like so (using react-localize-redux): const DefaultLanguage = withLocalize( ({ activeLanguage, setActiveLanguage, ...props }) => { useEffect(() => { console.log('setting active language'); setActiveLanguage(props.match.params.lang); }, []); return <></

How to call separate code for every single prop in useEffect

走远了吗. 提交于 2020-01-05 03:48:28
问题 I would like to make useEffect method, which is calling when any prop is changed but not all the code, just a single one dedicated for this props I imagine something like that ... In this moment all the code is called whed one, two or three is changed. const SomethingComponent = (props: any) => { const {one, two, three} = props; useEffect(() => { if(something for one props){ code for one } if(something for two props){ code for two } if(something for three props){ code for three } }, [one, two