cor-state
TypeScript icon, indicating that this package has built-in type declarations

0.1.5 • Public • Published

Intuitive state management solution

Important! Currently in ideation state

npm i cor-state

Configuration

You can get any field by calling c with the field you want to access from the useCor. To batch updates you can set the fields c({ count: 0, name: "Back to no name again" });

// AnyComponent.js
function AnyComponent() {
  const { c } = useCor({
    keys: ["count", "name"], // rerenders only if count and name changes
    defaultValues: { // optional default values
      count: 0,
      name: "No name"
    }
  });
  return (
    <div>
      <p>{c("count")}</p>
      <p>{c("name")}</p>
      <button onClick={() => c({ count: c("count") + 1 })}>Set count</button>
      <input
        value={c("name")}
        placeholder="set name"
        onChange={(event) => c({ name: event.target.value })}
      />
      <button
        onClick={() => {
          c({ count: 0, name: "Back to no name again" });
        }}
      >
        Reset
      </button>
    </div>
  );
}
  
 

Dependents (0)

Package Sidebar

Install

npm i cor-state

Weekly Downloads

1

Version

0.1.5

License

MIT

Unpacked Size

34.6 kB

Total Files

20

Last publish

Collaborators

  • varinli