refnew-react
refnew react binding.
Last updated 2 years ago by hrsh7th .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install refnew-react 
SYNC missed versions from official npm registry.

refnew-react

refnew bindings for react.

install

npm install refnew refnew-react

Usage

Basic

// 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<State>();
export { Provider, Consumer, update };

ReactDOM.render(
  <Provider value={createInitialValue()}>
    <App />
  </Provider>,
  document.querySelector("#app")!
);
// App.ts
import { Consumer, State, update } from './';

const select = (state: State) => ({
  todos: state.todos
});
export const App = () => (
  <Consumer select={select}>
    {({ todos }) => (
      {todos.map(todo => <div onClick={onClick.bind(null, todo)}>{todo.title} - {todo.status}</div>)}
    )}
  </Consumer>
);

const onClick = (todo: { title: string; status: string; }) => {
  todo.status = 'done';
  update();
};

see

note

  • inspired by aweary/react-copy-write.
  • don't use production.

Current Tags

  • 0.0.2                                ...           latest (2 years ago)

2 Versions

  • 0.0.2                                ...           2 years ago
  • 0.0.1                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 2
Dependencies (2)
Dev Dependencies (15)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |