0xkee / stook Goto Github PK
View Code? Open in Web Editor NEWA minimalist design state management library for React.
Home Page: https://stook.vercel.app/
License: MIT License
A minimalist design state management library for React.
Home Page: https://stook.vercel.app/
License: MIT License
比如一个请求耗时较长,然后我切换到其他的路由,但是请求还在继续。。
请问有计划支持class component吗?
export const StoreKey = {
a: 'a',
b: 'b',
c: 'c',
};
export type StoreKeyType = keyof typeof StoreKey;
使用的时候就可以提示可选的 store 值
useStore<StoreKeyType>('x', 0) // 这样就会报错,因为 x 不在 StoreKey 中
这样一方面能够有提示,另一方对大型项目可以作为相应的约束参照
有必要增加一个针对 key 的销毁机制吗?
我使用 useFetch 获取页面数据,在我首次进入这个页面的时候,useFetch 是工作的,但是当我第二次进入的时候,useFetch 不工作了,但是useEffect 还会继续工作,请问这两者更新有什么不同呢?
目前的useStore只要组件订阅了key, setState之后就会将发布订阅队列全部执行渲染,即使组件中没有用到store中的某些数据,能否实现类似redux的useSelector式API呢,另外还有一个问题就是目前这种方案,useStore中的数据初始化是在第二个参数中,两个组件订阅相同的key,初始化的数据将会以第一个先订阅为准,这样没约束规范吧,是否需要加一个store初始化的步骤呢
import * as React from "react";
import { render } from "react-dom";
import { useStore } from "stook";
function Display() {
const [count] = useStore("Counter", 100);
return <p>{count}</p>;
}
function Counter() {
const [count, setCount] = useStore("Counter", 8);
return (
<div>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>Click me</button>
</div>
);
}
// 调整 Display Counter 的位置会得到不同的初始值
function App() {
return (
<div>
<Display />
<Counter />
</div>
);
}
const rootElement = document.getElementById("root");
render(<App />, rootElement);
这种设计方式很容易出bug吧.....
by the way ,可以了解下Concent:
https://github.com/concentjs/concent
一个渐进式&高性能的增强型状态管理方案
这个项目挺好的,但是有个问题,目前我使用Redux一部分原因是为了实现React内和外部另外一个渲染程序(WebGL)的数据双向绑定的,看了下API文档,好像在外部只能读取指定状态,没法订阅更新.
或者提供个Api,直接暴露原始Redux的stroe对象.:joy:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.