DEV Community

rajeshwari rajeshwari
rajeshwari rajeshwari

Posted on

how use prop Drilling,use state,useEffeact,useRef.

HOW To Use Props Drilling In React:

Define the data in a parent component: The data that needs to be shared with a deeply nested child component is typically defined as state or a variable within a higher-level parent component.

In the parent component, render the immediate child component and pass the data as a prop.
Enter fullscreen mode Exit fullscreen mode

jsx

## How To Use Usestate:
To use the useState Hook in React for managing state within functional components, follow these steps:

    Import useState: Begin by importing the useState Hook from the react library at the top of your functional component file. 


 import {useEffeact } from 'react' ;
funtion My componut () {

UsEffeact (() => {

})

}

## how to useref in react;
The useRef hook in React provides a way to create a mutable reference that persists across component renders without causing re-renders when its value changes. It is commonly used for: Accessing and interacting with DOM elements.
import, {useref ,usestate} from 'react';
funtion My componunt(){
const inputRef = useRef(nall);
useeffact (()=> {
if (inputRef.current) {
          inputRef.current.focus();
        }
      }, []);

      return <input type="text" ref={inputRef} />;
    }.













Enter fullscreen mode Exit fullscreen mode

Top comments (0)