score:0
usestate in reactjs is asynchronous, thus it takes certain milli seconds to update before which the component would have already been rendered. one approach i found working was to directly use the value returned from the methods rather than setstate.
<div classname="cardpage__favourite" onclick={togglefav}>
{checkfav() ? <i classname={`pi pi-star-fill cardpage__star`} /> :
<i classname={`pi pi-star cardpage__star`} />}
</div>
also once you set the isfav using setisfav, you can use its value in other methods using the state variable isfav.
score:0
if (icons[i].id.tostring() === itemid) {
converting the id
to tostring()
will help you solve your query since you're also checking for type using ===
.
Source: stackoverflow.com
Related Query
- How to get the value of the span element with testid using react testing library?
- Invalid hook call. How to set a value with react axios get call?
- How to get the TextField value with onclick button event React Material UI
- how to get, by a get from axios, data in useState with react functionnal component
- How to get the value of Antd Form with React Hooks?
- React context value with typescript, not able to get the useState
- How to get a div's text value with react testing library?
- how to get value of input tag in array with same attribute name in react js
- How to get correct value with useState() in React?
- how to get updated value of react useState hook from setInterval function in highcharts?
- How to get the value of a dynamicly created input field with react
- How can I add an element to a list with a key value using a useState Record type in React typescript?
- How to update value of a key in object in an array with the new value in React useState in TypeScript
- How to get selected value by default if value match with other value in React Selectbox?
- how to get the value of two p tag in react using useState in ReactJs
- How to change a value from parent component in a child component with useState React hook
- How to get the changed (new) state value in React JS function with / without useEffect hook?
- How to get correct width of element with ref in react componentDidUpdate
- How to use callback with useState hook in react
- React Hooks - How to get parameter value from query string
- How to prevent race conditions with react useState hook
- useState with boolean value in react
- how to get code coverage in react with react testing library
- How can I get an input's value on a button click in a Stateless React Component?
- how to get selected value onChange of react redux-form drop down
- How to get value from a react function within a react component
- How to use React Context with useState hook to share state from different components?
- How to receive select value in handlesubmit function with formik react js?
- React Bootstrap. How to get value of Form.Control?
- How to get the marquee effect with list view in react native?
More Query from same tag
- How to manage UI feedback?
- Cannot find module '@material-ui/core'
- How to collapse react-bootstrap accordion panel horizontally?
- React - i18next-extract: Question about extractedTranslations output
- How can I use an scss file in my reactjs app?
- How to use Zebradatepicker in Reactjs?
- Setting attributes on click in React JS
- ReactJS error when passing a function as a props
- How can I 'mock' state value in ReactJS component unittest?
- Scroll-then-fix css grid column in ReactJS
- How render a list of options with renderOption in material UI
- build script don't runs when creating a Node.js and React app in Visual Studio
- Can you overwrite styles in Material UI using css/scss?
- How to render data from api like this
- Mount a child component again for a new game
- ReactJs: Load More pagination type (append)
- Unable to add svg icon to CardHeader in Material UI
- Trying to add scroll event listener on window, but getting Uncaught TypeError: Cannot read property 'classList' of null
- Were to make calculations on data from react-redux?
- How to type a higher order component with flow
- Cannot install react-export-excel using npm in reactjs
- How to use my react component PlaceInput to achieve place autocomplete in the menu input box?
- useState hook losing map data on page refresh
- How to change date format in reactjs like (17-Jun-2022)
- How to show a different div in react 16 when a boolean changes from false to true?
- File streamed from node and made into blob on javascript client is much larger and corrupted
- Fetching data from mongo via express, build object, and send to React
- How to mock <AppContenxt.Consumer> in React using Jest and Enzyme
- Content's div does not fully stretch horizontally
- Warning: A component is changing a controlled input of type file