JIYIK CN >

Current Location:Home > Learning > WEB FRONT-END >

All

Get parent height and width in React

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

Get parent height and width in React

To get the height and width of the parent in React: Set the ref attribute on the element. In the useEffect hook, update the state variables for height and width. Use the offsetHeight and offsetWidth properties to get the height and width of the elemen...

Full

How to listen to state changes in React

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

How to listen to state changes in React

Use the useEffect hook to listen to state changes in React. We can add the state variable we want to track to the hook's dependencies array, and the logic in the useEffect hook will run every time the state variable changes....

Full

Insert style tags into React components

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

Insert style tags into React components

To insert a style tag in a React component, wrap our css in a template string in a style tag. The expression between the curly braces will be evaluated and the style will be added....

Full

How to create a read more/less button in React

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

How to create a read more/less button in React

When building a web application, sometimes we need to display some long text. In this case, a smart design is to display only part of the text and add a Show More button for users to expand the text when needed. When the text is expanded and fully dis...

Full

Creating a Back Button with React Router

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

Creating a Back Button with React Router

To create a back button using React Router: Set the onClick property on the button to a function. Use the useNavigate() hook, e.g. const navigate = useNavigate();. Call the navigate() function, passing it -1 - navigate(-1)....

Full

How to toggle a boolean state in React

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

How to toggle a boolean state in React

Toggle Boolean state in React: Use the useState hook to track the state of a boolean. Pass a function to the setState function returned by the hook. Toggle the boolean based on the current value, e.g. setIsLoading(current => !current)....

Full

React: How to upload multiple files using Axios

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

This concise article shows you how to upload multiple files in React with the help of Axios. It’s not a big job and can be done in a few simple steps (you’ll see the Javascript and TypeScript code snippets in step 3)....

Full

Using onClick on Div Elements in React

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

Using onClick on Div Elements in React

To set an `onClick` listener on a div element in React: Set the `onClick` property on the div. Every time the div is clicked, the function we passed to the prop will be called. We can access the div via event.currentTarget....

Full

How to use buttons as links in React

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

How to use buttons as links in React

To use a button as a link in React, wrap the button in a tag, or in a Link component if using react router. The button will be rendered instead of a link, and clicking it will cause the browser to navigate to the specified page....

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

Scan to Read All Tech Tutorials

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

Hottest

Tags

Scan the Code
Easier Access Tutorial