
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
keep-react-alive
Advanced tools
#keep-react-alive
npm install keep-react-alive --save
# or
yarn add keep-react-alive
example
import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter as Router, Route, Link, Switch } from 'react-router-dom'
import Home from './components/Home';
import UserList from './components/UserList';
import UserAdd from './components/UserAdd';
import { KeepAliveProvider, withKeepAlive } from 'keepalive-react-component';
let KeepAliveHome = withKeepAlive(Home, { cacheId: 'Home'});
let KeepAliveUserList = withKeepAlive(UserList, { cacheId: 'UserList',scroll:true});
let KeepAliveUserAdd = withKeepAlive(UserAdd, { cacheId: 'UserAdd' });
const App = () => {
return (
<Router >
<KeepAliveProvider>
<ul>
<li><Link to="/">首页</Link></li>
<li><Link to="/list">用户列表</Link></li>
<li><Link to="/add">添加用户</Link></li>
</ul>
<Switch>
<Route path={'/'} component={KeepAliveHome} exact />
<Route path={'/list'} component={KeepAliveUserList} />
<Route path={'/add'} component={KeepAliveUserAdd} />
</Switch>
</KeepAliveProvider>
</Router>
)
}
ReactDOM.render(<App/>, document.getElementById('root'));
example\components\Home.js
import React from 'react';
const Home = (props) => {
return (
<div>
<button onClick={() => props.dispatch({ type: 'DESTROY', payload: { cacheId: 'UserAdd' } })}>重置UserAdd</button>
<button onClick={() => props.dispatch({ type: 'DESTROY', payload: { cacheId: 'UserList' } })}>重置UserList</button>
</div>
)
}
export default Home;
example\components\UserAdd.js
import React from 'react';
const UserAdd = ()=>{
let [number,setNumber]=React.useState(0);
return (
<div>
用户名:<input/>
<hr/>
<button onClick={()=>setNumber(number=>number+1)}>{number}</button>
</div>
)
}
export default UserAdd;
example\components\UserList.js
import React from 'react';
import {Link} from 'react-router-dom'
const UserList = (props)=>{
let users = new Array(100).fill(0);
return (
<ul style={{height:'200px',overflow:'scroll'}}>
{
users.map((item,index)=>(
<li key={index}><Link to={`/detail/${index}`}>{index}</Link></li>
))
}
</ul>
)
}
export default UserList;
FAQs
react版本的keep-alive组件
We found that keep-react-alive demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.