use-state

React setting state in useState hook

北城以北 提交于 2020-08-27 21:45:19
问题 I have problem with updating my state using useState hook. So in my "App" component, I declare my array of objects state: const [panelSettings, setPanelSettings] = useState([ { title: 'Background', active: true, options: [], updateDaily: true }, { title: 'Time and Date', active: true, showSeconds: true }, { title: 'Weather Forecast', active: false, city: null }]) Then I pass {panelSettings} and {setPanelSettings} down to another component, let's call it "Menu". In this "Menu" component I

Why does my create-react-app console.log twice?

家住魔仙堡 提交于 2020-06-23 14:53:11
问题 I'm just making a simple recipe fetching app using the create-react-app setup, but when I tried logging the response it logged it twice. I went backwards and deleted code until it stopped happening and for whatever reason it starts when I use the state hook: import React, { useState } from 'react'; import './App.css'; function App() { const APP_ID = '092fa53f'; const APP_KEY = '6fcf8c591c129cc3d01aefbda0d8a4d8'; const recipe_url = `https://api.edamam.com/search?q=chicken&app_id=${APP_ID}&app

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