# react-timeout **Repository Path**: mirrors_DylanVann/react-timeout ## Basic Information - **Project Name**: react-timeout - **Description**: Component wrapper for setTimeout et al that cleans up after itself. - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-08-08 - **Last Updated**: 2026-11-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # React Timeout [](https://greenkeeper.io/) [](https://travis-ci.org/plougsgaard/react-timeout) [](https://badge.fury.io/js/react-timeout) > Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op. > 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. Seeing a lot of the above? If so this might be useful! React Timeout is a higher order component for [React](https://github.com/facebook/react) and [React Native](https://github.com/facebook/react-native) providing the wrapped component with **safe** versions of Set | Clear ------------------------|------------------------ `setTimeout` | `clearTimeout` `setInterval` | `clearInterval` `setImmediate` | `clearImmediate` `requestAnimationFrame` | `cancelAnimationFrame` When the wrapped component is *unmounted*, any lingering timers will be canceled automatically. # Installation `npm install --save react-timeout` ## React / React Native ```javascript import ReactTimeout from 'react-timeout' ``` # Examples ## ES6 Classes - "The Light Switch" The component simulates a light switch. It has a state `on` which is `true` or `false`. When the button is clicked it waits `5000ms` before switching the `on` state. ```javascript import React from 'react' import ReactTimeout from 'react-timeout' class LightSwitchExample extends React.Component { state = { on: false } toggle = () => { this.setState({ on: !this.state.on }) } handleClick = (e) => { this.props.setTimeout(this.toggle, 5000) // call the `toggle` function after 5000ms } render () { return (