JIYIK CN >

Current Location:Home > Learning >

All

Update object state array in React

Publish Date:2025/03/09 Author:JIYIK Category:React

Update object state array in React

To update an array of object state in React: Use the map() method to iterate over the array. In each iteration, check if a condition is met. Update the properties of the objects that meet the condition....

Full

Update state when props change in React

Publish Date:2025/03/09 Author:JIYIK Category:React

Update state when props change in React

To update state when props change in React: pass props as dependencies to the useEffect hook. Every time props change, the logic in useEffect will re-run....

Full

How to handle visibility: hidden in React

Publish Date:2025/03/09 Author:JIYIK Category:React

How to handle visibility: hidden in React

Setting the CSS visibility property to hidden in React: Store a boolean value in the state indicating whether the element should be visible. Conditionally set the visibility property in the element's style attribute. For example, style={{visibility: i...

Full

How to create a Sleep function in React.js

Publish Date:2025/03/09 Author:JIYIK Category:React

How to create a Sleep function in React.js

To create a sleep function in React: Define a function that takes a number of milliseconds as a parameter. The function should return a Promise that is resolved after the provided number of milliseconds....

Full

Remove an object the state array in React

Publish Date:2025/03/09 Author:JIYIK Category:React

Remove an object the state array in React

To remove an object from the state array in React: Use the filter() method to iterate over the array. In each iteration, check if the condition is met. Set the state to the new array returned by the filter method....

Full

Setting onClick listener on links in React

Publish Date:2025/03/09 Author:JIYIK Category:React

Setting onClick listener on links in React

To set an onClick listener on a link in React: Set the onClick property on the link. Every time the link is clicked, the function we passed to the props will be called....

Full

Run React hooks when a component unmounts

Publish Date:2025/03/09 Author:JIYIK Category:React

Run React hooks when a component unmounts

Use the useEffect hook to run react hooks when the component is unmounted. The function we return from the useEffect hook is called when the component is unmounted and can be used for cleanup purposes....

Full

How to call a function only once in React

Publish Date:2025/03/09 Author:JIYIK Category:React

Use the useEffect hook to call a function only once in React. When the useEffect hook is passed an empty dependencies array, it runs only when the component mounts. This is the preferred approach when we have to fetch data when the component mounts....

Full

Replace objects in array in React state

Publish Date:2025/03/09 Author:JIYIK Category:React

Replace objects in array in React state

To replace an object in an array in React state: Use the map() method to iterate over the array. In each iteration, check if a certain condition is met. Replace the objects that meet the condition and return all other objects as is....

Full

Detecting when the Esc key is pressed in React.js

Publish Date:2025/03/08 Author:JIYIK Category:React

Detecting when the Esc key is pressed in React.js

To detect when the Esc key is pressed in React.js: Add a keydown event listener to the document element. When the user presses a key, check if the key is Esc. If the key pressed is Escape, call a function or run some logic. import {u...

Full

Check if browser tab has focus using React

Publish Date:2025/03/08 Author:JIYIK Category:React

Check if browser tab has focus using React

To check if a browser tab has focus using React: Add event listeners for the focus and blur events. If the focus event is fired, the tab has focus. If the blur event is fired, the tab loses focus. import {useE...

Full

How to remove query parameters using React Router

Publish Date:2025/03/08 Author:JIYIK Category:React

How to remove query parameters using React Router

To delete query parameters using React Router: Use the useSearchParams hook to get the search parameters for the current location. Use the delete() method to delete each query parameter, such as searchParams.delete('q'). To update the search parameter...

Full

How to render a boolean value in React JSX

Publish Date:2025/03/08 Author:JIYIK Category:React

How to render a boolean value in React JSX

In React, we use the String() function to render boolean values ​​in JSX, for example, h2{string(bool1)}/h2 . By default, boolean values ​​don’t render anything in React, so we have to convert the value to a string in order to render it. exp...

Full

Creating a numbers-only input field in React.js

Publish Date:2025/03/08 Author:JIYIK Category:React

Creating a numbers-only input field in React.js

To create an input field in React.js that only contains numbers: Set the input field's type to text . Add an onChange event handler that removes all non-numeric values ​​. Save the input value in a state variable. import { useState } from reactjs...

Full

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Hottest

Tags

Scan the Code
Easier Access Tutorial