@sedux/react
v0.1.1
Published
React bindings for Sedux state management library.
Readme
@sedux/react
React bindings for Sedux state management library.
Installation
npm install @sedux/react
# or
yarn add @sedux/react
# or
pnpm add @sedux/reactUsage
import { createStore } from '@sedux/core';
import { useStore, useDispatch, useSelector } from '@sedux/react';
// Create your store
const store = createStore({
// your store configuration
});
// Wrap your app with the store provider
function App() {
return (
<StoreProvider store={store}>
<YourApp />
</StoreProvider>
);
}
// Use hooks in your components
function Counter() {
const count = useSelector((state) => state.counter);
const dispatch = useDispatch();
return (
<div>
<p>Count: {count}</p>
<button onClick={() => dispatch({ type: 'increment' })}>
Increment
</button>
</div>
);
}API
StoreProvider
A React component that provides the Sedux store to the component tree.
<StoreProvider store={store}>
<App />
</StoreProvider>useStore
A hook that returns the Sedux store instance.
const store = useStore();useDispatch
A hook that returns the dispatch function from the store.
const dispatch = useDispatch();useSelector
A hook that allows you to extract data from the store state.
const selectedData = useSelector((state) => state.someData);License
MIT
