All Projects → jmlweb → isMounted

jmlweb / isMounted

Licence: MIT license
React hook to check if the component is still mounted

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to isMounted

storken
🦩 Storken is a React State Manager. Simple as `useState`.
Stars: ✭ 22 (-76.34%)
Mutual labels:  hook, state
React Loads
React Loads is a backend agnostic library to help with external data fetching & caching in your UI components.
Stars: ✭ 268 (+188.17%)
Mutual labels:  hook, state
Useeffectreducer
useReducer + useEffect = useEffectReducer
Stars: ✭ 642 (+590.32%)
Mutual labels:  hook, state
BaiDuYunCrack
iOS百度云盘 破解速度限制、去广告、去更新 无需越狱~
Stars: ✭ 82 (-11.83%)
Mutual labels:  hook
SwiftLoadHook
Use a hack way to achieve similar functions as Load() or initialize() in OC
Stars: ✭ 21 (-77.42%)
Mutual labels:  hook
hoox
Functional react state management base on hooks
Stars: ✭ 80 (-13.98%)
Mutual labels:  hook
ProcessInjector.NET
Learning Process Injection and Hollowing techniques
Stars: ✭ 23 (-75.27%)
Mutual labels:  hook
Uatu
Android方法调用跟踪 ; 方法耗时统计 ; 方法调用参数以及返回值跟踪 ; 方法调用替换;方法hook
Stars: ✭ 93 (+0%)
Mutual labels:  hook
snap-state
State management in a snap 👌
Stars: ✭ 23 (-75.27%)
Mutual labels:  state
kthook
No description or website provided.
Stars: ✭ 55 (-40.86%)
Mutual labels:  hook
PEDetour
modify binary Portable Executable to hook its export functions
Stars: ✭ 59 (-36.56%)
Mutual labels:  hook
elf-ng-router-store
Bindings to connect Angular router to Elf
Stars: ✭ 20 (-78.49%)
Mutual labels:  state
XUI
XUI makes modular, testable architectures for SwiftUI apps a breeze!
Stars: ✭ 100 (+7.53%)
Mutual labels:  state
hookman
A plugin management system in python to applications (in totally or partially) written in C++.
Stars: ✭ 29 (-68.82%)
Mutual labels:  hook
react-hook-videojs
Easy React integration of Video.js using hooks.
Stars: ✭ 37 (-60.22%)
Mutual labels:  hook
rex-state
Convert hooks into shared states between React components
Stars: ✭ 32 (-65.59%)
Mutual labels:  state
klyva
A state management library that follows the React component model
Stars: ✭ 53 (-43.01%)
Mutual labels:  hook
AndroidSec
记录一些我自己在学习Android逆向过程中的有意思的东西
Stars: ✭ 565 (+507.53%)
Mutual labels:  hook
ReSift
A state management library for data fetches in React
Stars: ✭ 39 (-58.06%)
Mutual labels:  hook
boutique
Immutable data storage
Stars: ✭ 44 (-52.69%)
Mutual labels:  state

isMounted

hook to check if your component is still mounted

Changing the state in an unmounted component will result in an error like this:

Warning: Can only update a mounted or mounting component. This usually means you called setState, replaceState, or forceUpdate on an unmounted component. This is a no-op.

But in some cases (promises derived from an api call, timeouts or intervals...) it's impossible to know if the component is still mounted or not.

😎 Use this hook and avoid errors

import React, { useState, useEffect } from 'react';
import useIsMounted from 'ismounted';
import myService from './myService';
import Loading from './Loading';
import ResultsView from './ResultsView';

const MySecureComponent = () => {
  const isMounted = useIsMounted();
  const [results, setResults] = useState(null);

  useEffect(() => {
    myService.getResults().then(val => {
      if (isMounted.current) {
        setResults(val);
      }
    });
  }, [myService.getResults]);

  return results ? <ResultsView results={results} /> : <Loading />;
};

export default MySecureComponent;

Installing

npm install ismounted or yarn add ismounted

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].