JIYIK CN >

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

All

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

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

Make an Http request on click in React

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

Make an Http request on click in React

To make an http request on click in React: Set an onClick attribute on the element. Every time the element is clicked, an HTTP request will be made. Update the state variables and render the data....

Full

Styling the border CSS property in React

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

Use the border css property to set the border style of elements in React, such as div style={{border: '1px solid rgba(0,255,0,0.3)'}}. If we only need to style a specific border, use the corresponding property, such as borderBottom....

Full

Get the height of an element in React

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

To get the height of an element in React: Set a ref attribute on the element. In the useLayoutEffect hook, update the state variable for the height. Use the clientHeight property to get the height of the element....

Full

Conditionally setting styles in React

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

Conditionally setting styles in React

To conditionally set styles in React: Set the `style` property on an element. Use the ternary operator to conditionally set the value of a CSS property. For example, backgroundColor: count > 0 ? 'lime' : 'salmon'....

Full

Setting global font family in React

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

Setting global font family in React

To set a global font family in React, you need to set the font-family style on the html element in your index.css file and then import the file into your index.js file. The global CSS should be imported in index.js to ensure it is loaded into your Rea...

Full

Using substring() method in React

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

To use the substring() method in React: Call the method on a string. Pass the start and end index as parameters to it. The method returns a new string containing only the specified portion of the original string....

Full

Scan to Read All Tech Tutorials

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

Hottest

Tags

Scan the Code
Easier Access Tutorial