Reactjs – useState in import
I get an error when I use useState in my App.js saying "Cannot use useState at a top level". I created a component in src folder called Box.js containing an array with 6 objects each with two properties; id and…
I get an error when I use useState in my App.js saying "Cannot use useState at a top level". I created a component in src folder called Box.js containing an array with 6 objects each with two properties; id and…
I have a simple translation function that takes one parameter(string) and return string. It works fine when i use like await translation(key) how ever my need it to use it frequently inside in react native component like below <Text>{tranlate("faqs")}</Text> Then…
I'm building a project with vite + react app. I fetched data in useEffect() and got the following error in console: GET https://opentdb.com/api.php?amount=5&category=9&difficulty=medium&type=multiple 429 (Too Many Requests) Here's my code : import React,{useState,useEffect} from 'react' function QuizMain() { const[data,setData] =…
I was working on a project that fetches data from swiggy api, but now I have added routing to the project. I don't know how can I use a state variable outside of the component but in the same file.…
I expect my console.log to show the current value of prevValueRef each one second. I checked and I saw that prevValueRef is increasing each second but it doesn't show it in the console each second while I console it after…
I have some interesting behaviour that I'm trying to understand in my React Application below. I'm finding form values aren't resetting when a user starts a new form submission and I'm trying to understand why. We have a Dashboard component,…
My component in react js: import React, { useState } from 'react'; const ComponentA = ({ children }) => { const [state1, setState1] = useState('Hello'); const [state2, setState2] = useState('World'); // Your component logic here return <div>{children}</div>; }; export default…
I haven't found any similar implementations, so I'm wondering if this is a valid thing to do in React? Problems with useState It's prone to stale value (which can happen in non-obvious ways). Example codepan. Note the oddCounter is 0,…
Workin on a react native application, getting this error: WARN Possible Unhandled Promise Rejection (id: 1): TypeError: setAuthenticated is not a function (it is undefined) This is my AuthPage where setAuthenticated is called: const AuthenticationPage = ( { setAuthenticated })…
I am trying to call parent function on button click . I am not aware how to achieve this . parent component export default function Message({ component }) { const [state, setState] = useState(false); const showMessage = ({ component })…