@ronin-react/react-keep-alive
TypeScript icon, indicating that this package has built-in type declarations

1.0.10 • Public • Published

Usage

install

yarn add @ronin-react/react-keep-alive

import component

import {useState} from 'react'
import {KeepScope, KeepAlive} from '@ronin-react/react-keep-alive'

const ids = [Math.random().toString(36).slice(2), Math.random().toString(36).slice(2)]

const MyComponent = () => {
	const [num, setNum] = useState(0)
	return <>
		<button onClick={() => setNum(num === 0 ? 1 : 0)}>
		 click to varify
		</button>
		{num === 0 && <KeepAlive id={ids[0]}>
		  <div>{Math.random()}</div>
		 </KeepAlive>}
		 {num === 1 && <KeepAlive id={ids[1]}>
		  <div>{Math.random()}</div>
		 </KeepAlive>}
		</>
}

const App = () => {
	retutn <KeepScope><MyComponent /></KeepScope>	
}

hook

useRefreshModule: (modulename: string) => () => void

import {useRefreshModule} from '@ronin-react/react-keep-alive'

const MyComponent = () => {
	const fresh = useRefreshModule('otherModule')
	return <div onClick={fresh}></div>
}

Readme

Keywords

none

Package Sidebar

Install

npm i @ronin-react/react-keep-alive

Weekly Downloads

1

Version

1.0.10

License

MIT

Unpacked Size

6.74 kB

Total Files

5

Last publish

Collaborators

  • zhengy1995