shenjunru / react-fiber-keep-alive

A component that maintains component state and avoids repeated re-rendering.
MIT License
60 stars 1 forks source link
keep-alive react react-dom react-fiber

Keep-Alive for React DOM

npm downloads typescript LICENSE

<KeepAlive> is a component that maintains component state and avoids repeated re-rendering.

✨ Features

📦 Installation

npm install --save react-fiber-keep-alive

🔨 Usage

import React from 'react';
import ReactDOM from 'react-dom';
import KeepAlive from 'react-fiber-keep-alive';

const root = document.getElementById('root');

ReactDOM.render((
    <KeepAlive.Provider value={root}>
        ...
        <KeepAlive name="test">
            <YourComponent />
        </KeepAlive>
        ...
    </KeepAlive.Provider>
), root);

📝 API

💡 Tips

🏁 Tested

Examples

React v16.8+ / v17 / v18

React v18 (concurrent mode)

Class Component

Function Component

Other

🐛 Issues

If you find a bug, please file an issue on our issue tracker on GitHub.

📄 License

Copyright © 2022 Shen JunruMIT license.