0.9.2 • Published 5 years ago

@lequysang/react-hooks-context v0.9.2

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

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;