JIYIK CN >

Current Location:Home > Learning >

All

Styling the border-radius property in React

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

Use the borderRadius CSS property to set the border radius style of elements in React, such as div style={{border: 1px solid red, borderRadius: 30px}} . If we need to set the style of a specific border, use the corresponding property, such as borderBo...

Full

Export 'useHistory' in React was not found in react-router-dom

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

Export 'useHistory' in React was not found in react-router-dom

To fix the error Export useHistory was not found in react-router-dom , use the useNavigate hook instead, e.g. const navigate = useNavigate() . This hook returns a function that allows us to navigate programmatically. // ?️ import useNavigate...

Full

Setting default values for Input elements in React

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

Setting default values for Input elements in React

To set default values ​​for Input elements in React: Pass the default value as a parameter to the useState hook for controlled fields. Set the defaultValue property on uncontrolled input fields. import {useRef, useState} from react ; export defaul...

Full

Setting conditional initial values for useState in React

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

To set conditional initial values ​​for useState in React: Pass a function to the useState hook. Use a condition to determine the correct initial value for the state variable. The function will only be called on the initial render. import {useStat...

Full

Unable to enter text in the input box in React

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

To fix the issue of input fields not working in React, make sure to use the defaultValue property instead of the value of the uncontrolled input field. Alternatively, set an onChange property on the field and handle the change event. Here is an exampl...

Full

Type useState as array of strings in React TypeScript

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

Type useState as array of strings in React TypeScript

To type the useState hook in React as an array of strings, use the hook's generics, such as const [names, setNames] = useStatestring[]([]) . State variables can be initialized to an empty array or an array of strings, and only accept string values....

Full

JSX expressions must have one parent element error in React

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

JSX expressions must have one parent element error in React

When a component returns multiple elements, you get the React.js error JSX expression must have a parent element. To fix the error, wrap the elements in a parent div element or use fragments, such as h2One/h2h2Two/h2/ . Below is an example that produc...

Full

React Hook 'useEffect' is called conditionally error

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

React Hook 'useEffect' is called conditionally error

The error React hook useEffect is called conditionally occurs when we use the useEffect hook conditionally or after a condition that may return a value. To fix the error, move all React hooks above any condition that may return a value....

Full

Using Ref to get the value of input field in React

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

Using Ref to get the value of input field in React

To get the value of an input field using ref in React: Set the ref attribute on the input element. Access the value of the input field on the ref object, e.g. ref.current.value . import { useRef } from react ; const App = () = { const inputRef = useRe...

Full

Function components cannot have string references in React

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

Function components cannot have string references in React

When we use a string as a reference in a function component, we get the error Function components cannot have string refs. To fix the error, use the useRef() hook to get a mutable ref object that we can use as a reference inside a component....

Full

Focus input when clicking another element in React

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

Focus input when clicking another element in React

To focus an input when another element is clicked in React: Set a ref attribute on the input element. Set an onClick attribute on the other element. When the other element is clicked, focus the input, e.g. ref.current.focus() . import { useRef } from ...

Full

Setting a Div's height to cover the entire screen in React

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

To set the height of a Div in React to cover the entire screen, set its height to 100vh, for example div style={{height: 100vh}}.../div . When the element's height is set to 100vh, it covers 100% of the viewport height. const App = () = { return...

Full

Handling onChange events on Select elements in React

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

Handling onChange events on Select elements in React

To handle onChange event on select element in React: Set onChange attribute on select element. Save the value of selected option in state variable. Every time user changes the selected option, update the state variable. import {useState} from react...

Full

Generate option tags for select from array in React

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

Generate option tags for select from array in React

Generate option tags for select from array in React: Iterate the array using map() method. In each iteration, return an option element. Pass a unique key attribute to each option element. const App = () = { const arr = [ { value...

Full

Modify the value of Textarea using onChange in React

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

Modify the value of Textarea using onChange in React

To modify the value of a text area using onChange in React: Add an onChange property to the text area, setting it to a function. Store the value of the text area in the state via the useState hook. Update the state every time the user types in the tex...

Full

Scan to Read All Tech Tutorials

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

Hottest

Tags

Scan the Code
Easier Access Tutorial