Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

useforceupdatefromanywhere

Hamed22815MIT0.0.3TypeScript support: included
react, reactjs, typescript, useForceUpdate, useForceUpdateFromAnywhere, useForceUpdateFromAnyComponent, use Force Update From Any Component, use_Force_Update_From_Any_Component, amisa, amisa.me, amisa.co, amin system, امین سیستم

readme

useForceUpdateFromAnywhere

npm version npm downloads license

About

React hooks for force updating Components from anywhere by others Components. Force update from anywhere to those using a useForceUpdate hook with optional payload.

only pass component's name (it must be uniqe name) and one main object that has one function by name "forceName" without any implementation. after that in other Componete you can use mainObject.forceUpdate(componentName) and that Component going to update :)

Install

npm


npm i useForceUpdateFromAnywhere

Usage example

Basic

import { useForceUpdateFromAnywhere } from "useforceupdatefromanywhere"

function App(mainObject) {
  return (
    <main>
      <Component1 mainObject={mainObject} />
      <Component2 mainObject={mainObject}/>
    </main>
  )
}

function Component1(mainObject) {
  useForceUpdateFromAnywhere(mainObject, 'componentName1');

  return (
    <div>
      <button onClick={() => mainObject.forceToUpdate('componentName1')}>Force update only this component</button>
      <button onClick={() => mainObject.forceToUpdate('componentName2')}>Force update component 2</button>
      <DeeplyNestedComponentContainingComponent1 />
    </div>
  )
}

function Component2(mainObject) {
  useForceUpdateFromAnywhere(mainObject, 'componentName2');

  return (
    <div>
      <button onClick={() => mainObject.forceToUpdate('componentName1')}>Force update component 1</button>
      <button onClick={() => mainObject.forceToUpdate('componentName2')}>Force update only this component</button>
      <DeeplyNestedComponentContainingComponent2 />
    </div>
  )
}