useContext

Gets the value from a Context Provider component within the current component's heirarchy. If no provider is found, it will return the context's default value.

Example

import { createContext, useContext } from "kaioken"

const ThemeContext = useContext("light")

function App() {
  return (
    <ThemeContext.Provider value="light">
      <Button />
    </ThemeContext.Provider>
  )
}

function Button() {
  const theme = useContext(ThemeContext)

  return <button className={theme} />
}

Related