sphaget

0.0.1 • Public • Published

sphaget

WIP

Name....?

https://youtu.be/c1DDBtYqA4U?t=124

Usage

import React, { useEffect, useState } from 'react';
import { WithSphaget } from 'spahget';

function Handler({ state, _handleSomething, otherProp, ...props }) {
  return (
    <>
      <label>{otherProp}</label>
      <label style={{ marginRight: '8px', marginLeft: '8px' }}>{state.h}</label>
      <button onClick={_handleSomething}>Change</button>
    </>
  );
}

function useStateDefinitions() {
  const [h, setH] = useState('hello');
  return {
    h,
    setH,
  };
}

function useEffectDefinitons(state) {
  useEffect(() => {
    if (state.h === 'world') {
      setTimeout(() => {
        state.setH('world from effect');
      }, 1000);
    }
  }, [state]);
}

function _handleSomething() {
  this.setH('world');
}

export default WithSphaget(
  // Component
  Handler,
  {
    // Handlers to be passed with names
    _handleSomething,
  },
  //  state and effect runners, pass an empty object
  {
    useStateDefinitions,
    useEffectDefinitons,
  }
);

Readme

Keywords

none

Package Sidebar

Install

npm i sphaget

Weekly Downloads

0

Version

0.0.1

License

MIT

Unpacked Size

4.47 kB

Total Files

4

Last publish

Collaborators

  • barelyreaper