Untitled

mail@pastecode.io avatar
unknown
javascript
2 years ago
496 B
11
Indexable
Never
export const Context = createContext('data')

export const Home = () => {
  const [data, setData] = useState('')

  const value = {
    data,
    setData
  }

  return (
    <Context.Provider value={value}>
      <Section />
    </Context.Provider>
  )
}

export const Section = () => {
  const {
    data, setData
  } = useContext(Context)

  const changeContext = () => {
    setData('123')
  }

  return (
    <>
      <Button onClick={changeContext}>Click</Button>
      {data}
    </>
  )
}