Update state in a function
See original GitHub issueThis should be easy, so I’m probably missing something. I know how to update the state using the useStore hook inside a React component, but how do I update the store inside a functional component?
export function handleDeepLink(event) {
const setUser = useStore((state) => state.setUser); << // Not allowed
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
Using the State Hook - React
What does useState return? It returns a pair of values: the current state and a function that updates it. This is why we...
Read more >Updating a state inside a React function - Stack Overflow
import React, { Component } from 'react'; class App extends Component { state = { data:'AA', newData: 'AA AA' } newData1=()=>{this.state.data + ...
Read more >React - Normal State Update vs Functional State Update
If we pass a function to React's useState(), it would call that function and use the return value to initialize the state. import...
Read more >useState in React: A complete guide - LogRocket Blog
React Hooks: Update state ... The second element returned by useState is a function that takes a new value to update the state...
Read more >How to Use State in Functional React Components
The state update function is just a regular function. It's used in the onClick handler to replace the current state value. React's internal ......
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
So, you want to update the store outside a component, correct?
Here’s what you want:
@anastely You can add them inside too. It’s working because they never change in your use case.