Skip to content

eclass/useSideEffect

Repository files navigation

@eclass/use-side-effect

npm Build Status downloads dependencies devDependency Status

Hook para aplicar un efecto asociado a un objeto

Prerequisites

  • node >=10.16.3

Install

npm i @eclass/use-side-effect

Run tests

npm run test

Example 📖

useSideEffect() receives an initializer parameter and return two elements [getter, setter].

import useSideEffect from "@eclass/use-side-effect";

function App() {
  const [obj, setObj] = useSideEffect({
    name: "pedro",
    age: 29
  });

...

Problem / Resolution

When you have an object in your state and use some effect to update this state could make and infinity loop, with this implementation we compare if your object it's same key/value/order and if is it the same don't update your state again.

Author

👤 Ender Bonnet

📝 License

Copyright © 2019 Ender Bonnet enbonnet@pm.me (https://enbonnet.me/).
This project is MIT licensed.