1.0.10 • Published 2 years ago

@ronin-react/react-keep-alive v1.0.10

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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>
}
1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago