i’m fetching data from my backend api and setting the data to my state but it’s returning an empty array and idk why this happening even though in other components it works just fine this is my code : Answer I was just missing a return in the .map function
Tag: react-hooks
TypeError: Cannot read property ‘title’ and map of undefined React Hooks props problem
I have a Json file to be fetched. I fetched the data and can get the data in the console from App.js. But when I pass the data as props to my child component, it gives me an empty array and does not display the items. What could be the mistake here ? My json data and components are below
React hook form method – setValue – doesn’t work
I have some clearable select, and I want to reset the applets field in state to an empty array. the problem is that clearing the selection on UI with setValue(“applets”, []); not working for some reason, and I don’t understand why, and how to do it without reset method, which resets the whole state, not just single property as I
Using React Hooks, when I pass down a prop from parent to a child component, the prop in the child component is undefined
What am I trying to do? I’m trying to set an array of objects in which the value within the array is dependent on the parent component. What is the code that currently tries to do that? Here are the different files simplified: When I render the “filePaths” in the return() of the Child component, the “filePaths” is able to
convert array of full date to array of month in react
i try to convert array of date to array of month in react when i push convertedDateToMonths to array every time i rewrite month in output i got only 1 month when i do console.log(month) what i do wrong ? Answer You need to call the setMonth function with the updated table and not on each .map loop. So just
How to use useState to display a different language
I’m trying to do a function using useState to change the languages of my website. However, I’m having an issue thinking about the logic of how can it be done since I’m newbie. 1st question: How can I use the function “handleLanguage” to change the menu language when I click in <li>. 2nd question: Which would be the best way
How to assign fetched data to React state
I trying to fetch data of an object (in this example from https://api.themoviedb.org/3/movie/459151?api_key=f13446aa3541ebd88cf65b91f6932c5b) and I’m trying to assign it to state movie. However, when I console it out, it has value undefined (actually, it is consoled out twice, firstly with default values of state and secondly as undefined). How to solve it? Thanks Answer As it seems in the API
destructuring props in component getting different result
New to react world, trying to learn destructuring, have been reading about it but stuck here, if i do it like this function MList({action}) { // const data = [action];} i am just getting ‘cameras’. So how to destructure and get same result as with props below this is Mcard.js: This is inside MList komponent: i want to destructure this
How to replace Array in useState?
I want make program that table content is changed by user’s select. So I put empty array in useState, like this. And select html code: When I select option, data will be changed. But I don’t no how to do it with useState. These are data And my React code: I tried using map. But I don’t know how to
How to define an array with conditional elements in react
I have a arry called a tableFilterFields like this: I want to apply a condition that If prop was not undefined ….How should I do this? Answer It would be better to do the conditional operation outside the array definition. You can achieve this by conditionally doing push operation