Skip to content

Commit

Permalink
refactor: don't use react's default export (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thanaen authored May 1, 2024
1 parent 201a6dc commit 125b869
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/context.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { createContext } from "react";
import { createContext, useContext, useState } from "react";
import type { StoreApi, UseBoundStore } from "zustand";

export const createZustandContext = <
Expand All @@ -13,14 +13,14 @@ export const createZustandContext = <
children?: React.ReactNode;
initialValue: TInitial;
}) => {
const [store] = React.useState(() => getStore(props.initialValue));
const [store] = useState(() => getStore(props.initialValue));
return <Context.Provider value={store}>{props.children}</Context.Provider>;
};

return [
Provider,
((selector: Parameters<TStore>[0]) => {
const store = React.useContext(Context);
const store = useContext(Context);
if (store === null) {
console.error("Missing provider for context:", Context);
throw new Error("Missing provider for context");
Expand Down

0 comments on commit 125b869

Please sign in to comment.