Can't access state when use it with hooks component
See original GitHub issueconst [email, setEmail] = useState('')
const onVerify = response => {
console.log(email) ??
}
Email does not update state to the latest. when I set email state to ‘xxx’ (setEmail(‘xxx’))
but outside onVerify function can access email state console.log(email) // ‘xxx’
Can I use reapctcha with hook component?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:8
- Comments:7 (1 by maintainers)
Top Results From Across the Web
React Hook: Can't access states in the function - Stack Overflow
I want to use loading and data in the TrackItem component. – Wong. Nov 30, 2019 at 10:14. yeah then you ...
Read more >Accessing React State in Event Listeners with useState and ...
If you're using React hooks in a component with an event listener, your event listener callback cannot access the latest state.
Read more >How To Fix The React Hook 'useState' cannot be called in ...
Simply swap out useState with setState; Refactor your component into a function component if you specifically want to use useState. Both options ...
Read more >How To Manage State with Hooks on React Components
In this tutorial, you'll manage state on functional components using a method ... This tutorial will use hooks-tutorial as the project name.
Read more >Accessing previous props or state with React Hooks
Leverage the useRef, useState, usePrevious, and useEffect React Hooks to access previous props and states from within functional components.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes, it’s because it’s not rerendering the recaptcha component when the email updates. The way I got around this was to use a state variable for the captcha and then a useeffect which triggers on the captcha state change.
You’ll also need a button of some type to call the
recaptchaRef.current.execute();
.me too , i have to use https://github.com/dozoisch/react-google-recaptcha