An open API service indexing awesome lists of open source software.

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.

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.