Skip to content

Commit

Permalink
feat: 🚀 update zustand package
Browse files Browse the repository at this point in the history
  • Loading branch information
limuen committed Oct 24, 2024
1 parent 981ede4 commit 5760d8a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 22 deletions.
3 changes: 2 additions & 1 deletion apps/defaultProject/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.21.3",
"@limuen/utils": "workspace:*"
"@limuen/utils": "workspace:*",
"@limuen/stores": "workspace:*"
},
"devDependencies": {
"@types/react": "^18.2.43",
Expand Down
17 changes: 14 additions & 3 deletions apps/defaultProject/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
import { useState } from "react";
import { useEffect, useState } from "react";
import reactLogo from "./assets/react.svg";
import viteLogo from "/vite.svg";
import "./App.css";

import { logInfo } from "@limuen/utils/console";
import { useUserStore } from "@limuen/stores";

function App() {
const [count, setCount] = useState(0);
const { token, setToken } = useUserStore();
useEffect(() => {
setToken({ expireTime: 0, login: false, token: "" });
}, []);
logInfo("count", count, token);

const handleSetCount = () => {
setCount(count + 1);
setToken({ expireTime: 0, login: false, token: "token12312312312" });
};

logInfo("count", count);
return (
<>
<div>
Expand All @@ -21,10 +31,11 @@ function App() {
</div>
<h1>Vite + React</h1>
<div className="card">
<button onClick={() => setCount(count => count + 1)}>count is {count}</button>
<button onClick={handleSetCount}>count is {count}</button>
<p>
Edit <code>src/App.tsx</code> and save to test HMR
</p>
<p>{token?.token}</p>
</div>
<p className="read-the-docs">Click on the Vite and React logos to learn more</p>
</>
Expand Down
7 changes: 6 additions & 1 deletion packages/stores/module/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const useUserStore = create<UserStoreState>()(
persist(
set => ({
token: null,
loginToRoute: "",
loginToRoute: "12312",
setToken: token =>
set((state: UserState) => {
state.token = token;
Expand All @@ -27,3 +27,8 @@ export const useUserStore = create<UserStoreState>()(
)
)
);

useUserStore.setState({
token: null,
loginToRoute: "setState"
});
2 changes: 1 addition & 1 deletion packages/stores/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"dependencies": {
"immer": "^10.0.3",
"zustand": "4.5.2",
"zustand": "5.0.0",
"react-router-dom": "^6.21.3"
}
}
29 changes: 13 additions & 16 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5760d8a

Please sign in to comment.