Skip to content

Conversation

@casamia918
Copy link

In Provider from createStoreContext method, store instance creation should be seperated from Provider wrapper. Because, store instance can be used in the Provider wrapping component itself, like this.

const counterStore = store({
	count: 0,
}).actions((store) => ({
	increment: () => store.count.set(store.count.get() + 1),
}));
 
export const {
	useStore: useCounterStore,
        useProvideStore: useProvideCounterStore,
//	Provider: CounterStoreProvider,
        Context: CounterStoreContext,
//	withProvider: withCounterStoreProvider,
} = createStoreContext(counterStore);


const Counter = ({ customProp }: { customProp: string }) => {
	const counterStore = useCounterStore();
	const count = counterStore.count.use();
 
	return (
		<div>
			<p>Count: {count}</p>
			<button onClick={counterStore.increment}>Increment</button>
		</div>
	);
};
 
const App = () => {

        const storeInstance = useProvideCounterStore({ count: 1 })
        
	return (
	        <CounterStoreContext value={storeInstance}>
                      <Counter customProp="example" />
                      <button onClick={() => console.log("current count: ", storeInstance.count.get())}>
                           Print
                      </button>
	        </CounterStoreContext>
	);
};

@vercel
Copy link

vercel bot commented Jun 1, 2025

@casamia918 is attempting to deploy a commit to the me Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant