@lequysang/react-hooks-context

0.9.2 • Public • Published

react-hooks-context

simple react context wrapper with hooks

usage

npm i -S @lequysang/react-hooks-context

Wrap your Root app and give your value

import React, { useState } from 'react'
import { ContextProvider } from '@lequysang/react-hooks-context'

const App = () => {
  const [state, setState] = useState(0);
  const action = () => {
      console.log('your action');
  }
  return (
      <ContextProvider value={{ state, action }}>
        <div> Your React Root <div>
        // <View>Your React Native Root</View>
      </ContextProvider>
  );
};
export default App;

Get value back in your View

import { useValue } from '@lequysang/react-hooks-context';

const YourView = () => {
    const { state, action } = useValue();
    return (
        <div>{state}<div>
    )
}
export default YourView;

Package Sidebar

Install

npm i @lequysang/react-hooks-context

Weekly Downloads

1

Version

0.9.2

License

MIT

Unpacked Size

3.94 kB

Total Files

6

Last publish

Collaborators

  • lequysang