0.0.31 • Published 7 months ago

0i0 v0.0.31

Weekly downloads
30
License
MIT
Repository
github
Last release
7 months ago

0i0

use redux like api, but achieve context like api nested in component

demo

https://codesandbox.io/s/0i0-yq1n3

how to use

install

yarn add 0i0

it need a root just like Context

import React, { useState } from "react";
import Num1 from "./num1";
import Num2 from "./num2";
import { Provider } from "0i0";

export default function App() {
  const [num1, setNum1] = useState(0);
  const [num2, setNum2] = useState(0);
  return (
    <Provider
      value={{
        num1,
        setNum1,
        num2,
        setNum2
      }}
    >
      <Num1 />
      <Num2 />
    </Provider>
  );
}

Select state in fuction component:

import React, { memo } from "react";
import { useSelector } from "0i0";

function Num2() {
  console.log("i am rendering");
  const num2 = useSelector((state) => state.num2);
  const setNum2 = useSelector((state) => state.setNum2);
  return (
    <div>
      {num2}
      <button onClick={() => setNum2((num) => num + 1)}>num2 add one</button>
    </div>
  );
}

export default memo(Num2);

select state in class component:

import React, { memo } from "react";
import { connect } from "0i0";

class Num1 extends React.Component {
  render() {
    console.log("i am rendering");
    const { num1, setNum1 } = this.props;
    return (
      <div>
        {num1}
        <button onClick={() => setNum1((num) => num + 1)}>
          {" "}
          num1 add one{" "}
        </button>
      </div>
    );
  }
}

export default memo(connect(({ num1, setNum1 }) => ({ num1, setNum1 }))(Num1));

todo

  • test case
  • CICD
  • Fix Cannot update a component problem
0.0.31

7 months ago

0.0.30

7 months ago

0.0.29

10 months ago

0.0.28

10 months ago

0.0.26

12 months ago

0.0.27

12 months ago

0.0.25

12 months ago

0.0.23

12 months ago

0.0.24

12 months ago

0.0.22

12 months ago

0.0.21

12 months ago

0.0.20

12 months ago

0.0.18

12 months ago

0.0.19

12 months ago

0.0.16

12 months ago

0.0.17

12 months ago

0.0.14

12 months ago

0.0.15

12 months ago

0.0.13

1 year ago

0.0.11

1 year ago

0.0.12

1 year ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago

1.0.0

1 year ago

1.0.10

1 year ago