{"id":21571551,"url":"https://github.com/zheeeng/react-remountable","last_synced_at":"2025-04-10T14:20:59.213Z","repository":{"id":57343484,"uuid":"128349546","full_name":"zheeeng/react-remountable","owner":"zheeeng","description":"Maybe you need the remount api for re-mounting a React Component","archived":false,"fork":false,"pushed_at":"2023-04-25T06:07:35.000Z","size":21,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T13:02:57.158Z","etag":null,"topics":["forcemount","react","remount","remountable","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zheeeng.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-04-06T05:39:19.000Z","updated_at":"2023-04-25T06:07:34.000Z","dependencies_parsed_at":"2022-09-12T06:30:22.884Z","dependency_job_id":null,"html_url":"https://github.com/zheeeng/react-remountable","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zheeeng%2Freact-remountable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zheeeng%2Freact-remountable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zheeeng%2Freact-remountable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zheeeng%2Freact-remountable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zheeeng","download_url":"https://codeload.github.com/zheeeng/react-remountable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247974558,"owners_count":21026742,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["forcemount","react","remount","remountable","typescript"],"created_at":"2024-11-24T11:16:40.142Z","updated_at":"2025-04-10T14:20:59.194Z","avatar_url":"https://github.com/zheeeng.png","language":"TypeScript","readme":"# react-remountable\n\n[![NPM](https://nodei.co/npm/react-remountable.png?downloads=true\u0026downloadRank=true\u0026stars=true)](https://nodei.co/npm/react-remountable/)\n\n[![language](https://img.shields.io/badge/%3C%2F%3E-TypeScript-blue.svg)](http://typescriptlang.org/)\n[![license](https://img.shields.io/github/license/mashape/apistatus.svg)]()\n[![npm version](https://img.shields.io/npm/v/react-remountable.svg)](https://www.npmjs.com/package/react-remountable)\n\n* provides an API `remount` as prop for re-mounting component\n* resets stateful component to initial state\n* just use it like using the `ReactComponent::forceUpdate` API\n* re-calls phases: `componentWillUnmount` -\u003e `constructor` -\u003e `static getDerivedStateFromProps(v16.3+)` -\u003e `render` -\u003e collect refs -\u003e  `componentDidMount`\n\n## Why\n\nWe may need:\n\n* Refresh a component locally\n* Discard the mutated state data\n* Trigger some component life-cycle hooks\n\n## Installation\n\n```\nyarn add react-remountable\n```\n\nor\n\n```\nnpm install -s react-remountable\n```\n\n## Example:\n\n```jsx\nimport remountable from 'react-remountable'\nimport { StatefulForm1, StatefulForm2, StatefulForm3 } from './Forms'\n\n@remountable  // decorator syntax\nexport default class Dashboard extends React.Component {\n    state = { greeting: '', whatsUp: '' }\n\n    focusRef = (ref) =\u003e ref \u0026\u0026 ref.focus()\n\n    handleWhatsUpChange = (e) =\u003e {\n        this.setState({ whatsUp: e.target.value })\n    }\n\n    handleReset = () =\u003e {\n        // 1. send log\n        // 2. re-render/refresh Dashboard component and its stateful children components\n        // 3. auto focus on the text input\n        // 4. fetch today's greeting and render it\n        this.props.remount()\n    }\n\n    async componentDidMount () {\n        const { greeting } = await fetch('api.example.com/greeting').then(response.json())\n        this.setState({ greeting })\n    }\n\n    render () {\n        return (\n            \u003cdiv\u003e\n                \u003ch1\u003e{this.state.greeting}\u003c/h1\u003e\n                \u003cStatefulForm1 /\u003e\n                \u003cStatefulForm2 /\u003e\n                \u003cStatefulForm3 /\u003e\n                \u003cinput onChange={this.handleWhatsUpChange} ref={this.focusRef} /\u003e\n                \u003cbutton onClick={this.handleReset}\u003eReset\u003c/button\u003e\n            \u003c/div\u003e\n        )\n    }\n\n    componentWillUnmount () {\n        fetch('api.example.com/log', { method: 'POST', body: JSON.stringify({ action: 'reset'}) })\n    }\n}\n```\n\nIf the ESNext decorator syntax is not enabled:\n\n```js\nexport default remountable(Dashboard)\n```\n\n## Enjoy it!\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzheeeng%2Freact-remountable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzheeeng%2Freact-remountable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzheeeng%2Freact-remountable/lists"}