Questions tagged [setstate]

Use for questions relating to the [setstate] method and component/widget state management in [reactjs] and [flutter].

setState is a component method in and which updates the local component/"widget" state and triggers a re-render of the component based on the new state.

Resources

2626 questions
0
votes
2 answers

URL is not updating in React JS using setState

I am building a news app using React JS. I am using News API to collect the data. I added the next and previous buttons to show the next news by updating the URL using setState. But the problem is the URL is not updating. There is part of URL where…
0
votes
1 answer

The filter is not deleting each item in array while clicking on button. please assist

The filter is not deleting each item in the array while clicking on the button. the id from onclick event is being received correctly. the first element is also being deleted then it's not deleting another element. import React,{useState} from…
0
votes
1 answer

Have refreshed state in Hook in loop

Replacing the phrase - based on start and end index - by visibleText. The problem - there is multiple phrases(each phrase changing per iteration) . So the value of transformedText is not refreshing by setTransformedText hook. How to have changed…
Piotr Żak
  • 2,046
  • 5
  • 18
  • 30
0
votes
4 answers

Understanding React's setState method

I understand the below code adds a new object to an array of objects but fuzzy on a specific syntax: setProductList([array, obj]) From what I'm seeing, the setProductList function takes in an object. That object consists of an array and an object.…
Eric Nguyen
  • 926
  • 3
  • 15
  • 37
0
votes
2 answers

React Hooks SetState Method isn't updating the state at all

I am using a Material UI Select Component to render a simple drop down menu, with its value as a state declares using the useState method. const [collaboratingTeams, setCollaboratingTeams] = useState([]) The below code is of the Select…
0
votes
1 answer

Flutter http error when I try to use code that works in dart

I am new to flutter and I want to create app that will help me solve chemist equations, for that I created this function: void main() { String m = "H2O"; String n = "H2O"; parser(m, n); } parser(m, n) async { var client = Client(); …
aNOOBis
  • 70
  • 2
  • 6
0
votes
1 answer

I want to set state based on accessToken of cookies, but I can't access to cookies

I am using React and I want to access to cookies, specifically accessToken, so that I can setLogin(true) based on existence of accessToken. I tried document.cookies, react-cookies library, but I can't access to that cookies... even though I can see…
MarkCode
  • 3
  • 1
0
votes
1 answer

React How to re-render state hook with useEffect and useCallback?

I apologize for asking this question. I've read many posts on how to re-render the state but I still can't figure it out. I'm too noob :( I can get things to work with useRef, but I'd like to learn how to update state with useEffect and…
Levan Marston
  • 75
  • 1
  • 7
0
votes
2 answers

React setState - update object in array

I am using setState hook to set an object with an array similar to: const [organisations, setOrganisations] = useState({ items: [], hasMore: false, }); items array looks similar to this: [ 0: {id: "2", name: "Test Internal 5", isInternal:…
Paul
  • 219
  • 1
  • 3
  • 11
0
votes
1 answer

setState not working inside a simple if condition of a function

I am trying to setState in a function inside if condition but thee value is not getting updated. Please find below the code snippet archivePath = (filepath: string) => { if (filepath) { const breadcrumbs: any[] = []; …
Rani Agrawal
  • 39
  • 1
  • 6
0
votes
1 answer

change value of a nested object using setState hook in react

Need to change isClicked on click like a toggle to !isClicked. It renders JSX styles for a button click. My data: const [isApply, setIsApply] = useState([ { "0": { "isClicked": false, "isExpand": false, …
Himath
  • 3
  • 1
0
votes
1 answer

I am able to save but not able to fetch the saved notes dynamically from DB, when I restart the app the notes are displaying. I am using sqflite

I'm a beginner in flutter, I'm building a simple Note app where users can enter, edit and save the note in local db. I'm able to save the notes to DB but it is not fetched as soon as it is saved. I need to restart the app to see the note list. This…
0
votes
3 answers

How to loop in useEffect and setState

I have categories and every category has subcategories, and i want to setState a dictionary like {category1.name: [/*list of all subcategories*/], category2.name: [...]} and i have useEffect(()=>{ …
0
votes
2 answers

Refresh listview based on button click

I have a list of categories and products. I want that when I click on a category: The selected category should change color to orange. The products listview should be refreshed with the selected category's products. I tried to add setState and try…
mcfred
  • 1,183
  • 2
  • 29
  • 68
0
votes
0 answers

how to reset the variable value in flutter

I created a login form in where i am passing the username to dashboard screen using shared perference, problem is when i logged in from abc name and pass it to dashboard it is displaying correct name, but when i logged in from xyz name it display…
TimeToCode
  • 1,458
  • 3
  • 18
  • 60