JIYIK CN >

Current Location:Home > Learning >

All

Change button text on click in React

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

Change button text on click in React

To change the text of a button when clicked in React: Track the text of the button in a state variable. Set an onClick attribute on the button element. When the button is clicked, update the state variable....

Full

Using Ref to set input value in React

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

Using Ref to set input value in React

To set the value of an input field using ref in React: Set the ref attribute on the input element. When an event is triggered, update the value of the ref. For example, ref.current.value = 'New value'....

Full

Get the width and height of the window in React

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

Get the width and height of the window in React

To get the width and height of the window in React: Use the innerWidth and innerHeight properties of the window object. Add an event listener for the resize event in the useEffect hook. Save the changes in the window width and height in state variable...

Full

Redirecting to an external URL in React

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

Use the window.location.replace() method to redirect to an external url in React, for example, window.location.replace('https://www.jiyik.com'). We can programmatically replace the current resource with a new one by calling the replace() method if a c...

Full

Check if a string is empty in React

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

Check if a string is empty in React

To check if a string is empty in React, access its length property and check if it is equal to 0, for example if (str.length === 0) {}. If the length of the string is equal to 0, the string is empty, otherwise it is not empty....

Full

String concatenation in React props

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

Use template literals to concatenate strings in React attributes, such as div className={border ${myClass}}. Template literals are delimited by backticks, allowing us to embed variables and expressions using the dollar sign and curly brace ${expressio...

Full

Handling double click events in React

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

Handling double click events in React

To handle double click events in React: Add an `onClick` attribute to the element. Use the detail property of the event object to get the number of clicks. If the number of clicks is equal to 2, handle the double click event....

Full

Using forEach() method in React

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

The forEach() method can be used to iterate over an array outside of JSX code in React. If we need to iterate over an array and render its elements directly in JSX code, use the map() method instead....

Full

How to merge two arrays in React.js

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

Use the spread syntax ... to combine arrays in React, e.g. const arr3 = [...arr1, ...arr2]. The spread syntax is used to unpack the values ​​of two or more arrays into a new array. The same approach can be used to combine two or more arrays when s...

Full

Handling onKeyDown Events in React

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

Handling onKeyDown Events in React

To handle onKeyDown events in React: Set the onKeyDown prop on the element. Use the key property of the event object to get the key the user pressed. For example, if(event.key === 'Enter') {}....

Full

Changing the color of a link in React

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

Use css file to change the color of links in React. We can define the styles that apply to the anchor element and import the css file in the component to make the styles take effect....

Full

How to draw a horizontal line in React

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

How to draw a horizontal line in React

To draw a horizontal line in React: Use the hr/ tag and set the style attribute on it. Set the height of the line and optionally set the background color and colour....

Full

Scroll to bottom of div in React

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

Scroll to bottom of div in React

Scroll to the bottom of a div in React: Add an element to the bottom of the div. Set a ref on the bottom element. When an event occurs, call the scrollIntoView() method of the ref object....

Full

How to loop over objects in React

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

To loop over an object in React: Use the Object.keys() method to get an array of the object's keys. Use the map() method to iterate over the array of keys....

Full

How to use React lazy code splitting

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

React lazy function allows us to dynamically import components. We may want to do this to reduce the initial bundle size that the user must download to see the content on the screen....

Full

Scan to Read All Tech Tutorials

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

Hottest

Tags

Scan the Code
Easier Access Tutorial