4.6.0-beta.0 - The new State API
🦇 🎃 This is an initial beta release of the new State
API. The State API is a low-level way to create instances of hooks state. It provides methods for running hooks code and a callback for when any hook state has changed. The intended use-case is integration with base classes such as SkateJS and LitElement.
Since the API is lower-level, we feel it should be first released as a beta so developers interested in creating integrations with base classes can try it out and see if there are any holes to be filled. When those developers as satisfied it will come in a future minor release, likely 4.6.0.
Here's a small example of how the State
API works at its lowest level:
import { State, useState } from 'haunted';
let state = new State(() => {
update();
});
function update() {
state.run(() => {
const [count, setCount] = useState(0);
console.log('count is', count);
setTimeout(() => setCount(count + 1), 3000);
});
}
update();
More example integrations can be found in this gist. Also see the documentation in the readme here.