DEV Community

Slava Birch
Slava Birch

Posted on

Answer: Is it possible to share states between components using the useState() hook in React?

This is possible using the useBetween hook.

See in codesandbox

import React, { useState } from 'react'
import { useBetween } from 'use-between';

const useShareableState = () => {
  const [username, setUsername] = useState('Abrar');
  const [count, setCount] = useState(0);
  return {
    username,
    setUsername,
    count,
    setCount
  }
}


const HookComponent =

Top comments (0)