I have a react component that is trying to pass a function to another component, the problem is that I’m not being able to define the function, it throws a compiling error What am I missing? Rafael Answer You declared component as functional, but trying to create a class method. You should either use cl…
Tag: react-props
React Hooks: Passing state prop is NOT a function?
I am passing state hooks as props to my components and my ‘setCity’ works perfectly fine but when I try implementing setFlag I get an error saying “Searchbar.jsx:15 Uncaught TypeError: setFlag is not a function” So why can I set the value of city but not flag? I pass the props from …
Pass triggering button’s name as props to child modal in React
I am a beginner in React so please be patient with me )) I have a parent component with two different buttons that trigger a child component which is a Modal that must show different data inside it depending on which button has triggered the Modal. Both components are functional components. The child Modal is…
Why to use Object.assign() to update functional component props change?
I have a list of students and I display them on the table. There are two buttons that indicate by which value should I sort the list (name or birthdate). When the button is clicked and I sort the list, the list itself is getting sorted, but it’s not updating if I don’t assign the list to the new l…
Why my props action doesn’t work in an “if” statement in “onClick”, but it works outside the “if” statement?
This code works: This code doesn’t work: I’m new to reactjs Does any body know why it doesn’t work in the second way? Answer Just a tip; Make a function and then call the funciton onClick instead. The code gets simpler to read!
Save a prop when moving away and coming back to page ReactJS
I have a username property that I have passed on from “log in” route to “product list” route using I then have a <Link to={‘/products/${product.id}’}>More info</Link> that sends me from “product list” to an “individual product”. When I th…
Component doesn’t update once the parents state is changed
I’m attempting to get a timer to call a function quickly at first and then slow down. I have a TimeInterval state that increases and is passed down to my countdown component as a prop Countdown Component My TimeInterval state is working properly and will increase as NextSelection() is called. However th…
How do I stop state element being passed to child component before it is set?
I’m writing a weather forecast app with React. I’m fetching the data from openweathermap.org API. But to use that I need to know user’s location. So I use other API’s in sequence as well to identify user IP, location, and then weather data according to that location. At each fetching s…
Send multiple props across components React
I am trying to send two variables from the Component ‘Game’ to the Component ‘App’ but I am unsure how to send more than one prop at a time. This what I have: With this I am able to send the prop ‘score’ from ‘Game’ to ‘App’ but I was wondering if it…
Responsive Props In ReactJS Styled Components
I have an idea of how to do responsive props using Styled Components, but I can’t figure out how to implement it. My idea goes something like this: In this case color and bg are just props that I set in my styled component: The idea is that I have a top-level prop that is for a particular media query