ReactJS Hook Pattern ~Use Hook with Context~

Published: (January 16, 2026 at 03:56 AM EST)
1 min read
Source: Dev.to

Source: Dev.to

Cover image for ReactJS Hook Pattern Use Hook with Context

Using the use Hook with Context

  • In ReactJS 19, the use hook was introduced to provide a more flexible way of reading context values than the useContext hook.
  • The use hook can be called conditionally inside if statements and loops, making it ideal for achieving dynamic behaviour in components.
import { createContext, useContext, use } from "react";
import "./app.css";

const ThemeContext = createContext(null);

function Button({ show, children }) {
  if (show) {
    const theme = use(ThemeContext);
    const className = "button-" + theme;
    return { children };
  }

  return null;
}

function App() {
  return (
    <div>
      {/* UI elements go here */}
    </div>
  );
}

export default App;

Use Hook with Context

(The original article included this heading after the code snippet.)

Back to Blog

Related posts

Read more »