useInject
Read state provided by parent components
API Reference
Syntax
const count = useInject<number>("count");Parameters
key: Global state key to read
Returns
value: Latest state value, throws error if not found
Example
function App() {
useProvide("count", 0); // Provide state to child components
return <Child />;
}
function Child() {
const count = useInject<number>("count"); // Inject state
return <div>Count: {count}</div>;
}Notes
useInjectreads the latest value provided byuseProvide, not reactive.useProvideanduseInjectoperate on global state, not isolated by component tree.