I am trying to persist data to AsyncStorage using Zustand.
Here is my code for the store:
//store.ts
export const useAuthStore = create(
persist(
(set) => ({
token: "",
setToken: (token) =>
set((state) => ({
token: token,
})),
}),
{
name: "token",
getStorage: () => AsyncStorage,
}
)
);
Here is the code for my login page:
//login.tsx
const setStoreToken = useAuthStore((state) => state.setToken);
async function handleLogin() {
setStoreToken("6747rt345t67324xn487r364qxuhfu");
const storedToken = await AsyncStorage.getItem("token");
console.log(storedToken);
}
The console.log in login.tsx is here: {"state":{"token":"6747rt345t67324xn487r364qxuhfu"},"version":0}.
What I would like to get is "6747rt345t67324xn487r364qxuhfu", which is just the token without the session and version.