state with store not working
yathink3 opened this issue · comments
import { useState } from "react";
import createStore from "teaful";
const initialState = {
username: "Aral",
age: 31,
cart: {
price: 0,
items: []
}
};
export const { useStore, getStore, withStore } = createStore(initialState);
export default function CartFirstItem() {
const [state,setState] = useState(0);
const [item, setItem, resetItem] = useStore.cart.items[state]();
console.log("Render CartFirstItem", item);
return (
<>
<h2>Item: {JSON.stringify(item)}</h2>
<button
onClick={async() =>{
await setItem({ name: "new Item", price: (item?.price || 0) + 1 })
}}
>
Update item
</button>
<button onClick={()=>setState(2)}>change Index</button>
<button onClick={resetItem}>Reset item</button>
</>
);
}
on this example state index is changed to 2 , but still it not taken 2 index data
Thank you for reporting it @yathink3. I will try to reproduce and correct it today.
welcome, i liked this library than any other state management solution for react ,
its dynamic fetching is freaking awesome