https://github.com/hrsh7th/refnew-react
refnew react binding.
https://github.com/hrsh7th/refnew-react
Last synced: 2 months ago
JSON representation
refnew react binding.
- Host: GitHub
- URL: https://github.com/hrsh7th/refnew-react
- Owner: hrsh7th
- Created: 2018-08-12T17:12:28.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-08-13T15:06:57.000Z (about 7 years ago)
- Last Synced: 2025-02-03T17:02:19.340Z (8 months ago)
- Language: TypeScript
- Size: 5.86 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# refnew-react
refnew bindings for react.
# install
`npm install refnew refnew-react`
# Usage
### Basic
```ts
// index.ts
import { create } from "refnew-react";
import React from "react";
import ReactDOM from "react-dom";
import { App } from "./App";export type State = {
todos: {
title: string;
status: "in-progress" | "done";
}[];
user: {
name: string;
icon: string;
};
};const { Provider, Consumer, update } = create();
export { Provider, Consumer, update };ReactDOM.render(
,
document.querySelector("#app")!
);
``````ts
// App.ts
import { Consumer, State, update } from './';const select = (state: State) => ({
todos: state.todos
});
export const App = () => (
{({ todos }) => (
{todos.map(todo =>{todo.title} - {todo.status})}
)}
);const onClick = (todo: { title: string; status: string; }) => {
todo.status = 'done';
update();
};
```# see
- [refnew](https://github.com/hrsh7th/refnew)
# note
- inspired by `aweary/react-copy-write`.
- don't use production.