ReactJS: ';' expected while mapping over an array

I am trying to create an array of objects in the following manner: function allNewDice(){ const newDice = new Array(10).fill(0).map(x => { value: Math.ceil(Math.random() * 6), isOn : false } )} However next to isOn property, I am getting the error ‘;’ expected What am I doing wrong If I use a for loop to… Read More ReactJS: ';' expected while mapping over an array

My React app gets rerendered more than one time after a click event occurs even after using useEffect()

I am trying to call this endpoint to generate random memes when a a user clicks on a button. I am using the fetch api inside the useEffect hook,and the button works fine, but when I click it, there is splash of a new image for a split second and then the image disappears as… Read More My React app gets rerendered more than one time after a click event occurs even after using useEffect()

How to simulate expanding effect in bootstrap

I have this react code: const[open, setOpen] = useState(false); const zoom = () => { if(open){ setOpen(false); } else{ setOpen(true); } } return ( <div><button>zoom in and out</button></div> <div className="row"> <div className={`col col-${open ? ’12’ : ‘9’}`}> Content than can be expanded </div> { !open && <div className="col col-3"> content that gets hidden when zooming… Read More How to simulate expanding effect in bootstrap

Updating state data containing a nested array of objects

My state "data" consist of the following nested array of objects { "message": "Fetched films successfully.", "films": [ { "_id": "640685ea5d0f00f7f2e4c5b5", "title": "Catwoman: Hunted", "imageUrl": "images/5.png", "releaseDate": "2023-03-16T04:00:00.000Z", "reviewcnt": 4, "reviewavg": 3, "userlikecnt": 3 }, { "_id": "640685f05d0f00f7f2e4c5bf", "title": "Troll", "imageUrl": "images/1.jpg", "releaseDate": "2023-01-23T04:00:00.000Z", I’m trying to decrement the userlikecnt of filmID : 640685ea5d0f00f7f2e4c5b5 as… Read More Updating state data containing a nested array of objects

(Solved) Page refresh doesn't change the classNames to the localStorage value

I’m creating my first react app and I’m having some problems with the light and dark mode. When clicking the button to toggleLightDark function, it works as it saves the true or false state to the localstorage and that works fine. The problem is that when I refresh the page, for some reason when the… Read More (Solved) Page refresh doesn't change the classNames to the localStorage value

How do I access the div root body from the react?

I have such a html project structure: <div id="root"> <div class="main-c container-fluid> </div> … <div> My index.tsx: import ‘./index.css’; const root = ReactDOM.createRoot( document.getElementById(‘root’) as HTMLElement ); root.render( <React.StrictMode> <HashRouter> <App /> </HashRouter> </React.StrictMode> ); app: import "bootstrap/dist/css/bootstrap.min.css" function App() { return ( <Container className="main-c" fluid> … </Container> ); } And I don’t understand how… Read More How do I access the div root body from the react?