React Native
About Lesson

In this React Native video lesson we want to learn about useState Hooks in React Native, in this video we will practically learn about this concept.

 

What are React Native Hooks ?

In React Native hooks are functions that allow you to use state and other React features in functional components. they were introduced in React 16.8 as a way to add stateful logic to functional components without the need for class components.

There are several hooks available in React Native, including:

  1. useState: This hook allows you to add state to functional component. it returns an array with two values, current state value and a function to update the state.
  2. useEffect: This hook allows you to perform side effects in functional components such as fetching data from an API or updating the DOM. it takes a function as its first argument, which will be called after the component has rendered.
  3. useContext: This hook allows you to access a context object created by the React.createContext function. it takes context object as its argument and returns the current context value.
  4. useReducer: This hook allows you to manage state with reducer function similar to how it is done in Redux. It takes reducer function and an initial state as its arguments, and returns an array with the current state value and a dispatch function to update the state.
  5. useCallback: This hook allows you to memoize a function and only recompute it when its dependencies change. it takes a function and an array of dependencies as its arguments, and returns a memoized version of the function.
  6. useMemo: This hook allows you to memoize a value and only recompute it when its dependencies change. it takes a function and an array of dependencies as its arguments, and returns memoized version of the value.
  7. useRef: This hook allows you to create a mutable object that persists between renders. It returns an object with current property that can be used to store any mutable value.

 

What is useState Hooks ?

useState is React Native hook that allows functional components to have state. before the introduction of hooks functional components were stateless and could not maintain any internal state. useState hook provides an easy way to add state to functional components.

useState hook takes an initial value as its argument and returns an array with two values: the current state value and a function to update the state.

 

Using hooks can make your code more concise and easier to read as it allows you to manage state and other React features in functional components, without the need for class components.

Join the conversation