functional setState shows `no-unused-state`.
See original GitHub issueversion: 7.6.1
state = {
removeQueue: [], <--- unused state field: 'removeQueue'
}
onUpdate = (date, id) => {
this.setState(prevState => ({
removeQueue: [...prevState.removeQueue, { date, id }],
}));
}
I’m using removeQueue in functional setState, but eslint shows error.Unused state field: 'removeQueue' (react/no-unused-state)
I also maked onUpdate a constructor-bound instance method as @ljharb said.
constructor() {
super();
this.onUpdate = this.onUpdate.bind(this);
}
onUpdate(date, id) {
this.setState(prevState => ({
removeQueue: [...prevState.removeQueue, { date, id }],
}));
}
But it shows me same result…
Issue Analytics
- State:
- Created 6 years ago
- Reactions:11
- Comments:5 (1 by maintainers)
Top Results From Across the Web
functional setState shows no-unused-state . #1697 - GitHub
I'm using removeQueue in functional setState, but eslint shows error. Unused state field: 'removeQueue' (react/no-unused-state).
Read more >How do I avoid unused setState functions? Can React ...
setState is used when it's needed to be aware of the changes in the value stored in state. This way the component knows...
Read more >Using a function in `setState` instead of an object - Medium
Components that contain local state have a property called state When we want to change our how application looks or behaves, we need...
Read more >Using the State Hook - React
A Hook is a special function that lets you “hook into” React features. For example, useState is a Hook that lets you add...
Read more >What is the second argument that can optionally be passed to ...
log function is getting called on the previous value of input field. It shows the asynchronous nature of setState. 2. Passing a second...
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 Free
Top 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
We are getting bit by this too. Here’s my minimal example to reproduce:
Error:
Unused state field: 'unused' (react/no-unused-state)
+1, error happens on destructing like @lemonmade commented.