1.0.0 • Published 3 years ago

@jswork/react-sw-update-tips v1.0.0

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

react-sw-update-tips

Update tips for service-worker.

version license size download

installation

npm install -S @jswork/react-sw-update-tips

update

npm update @jswork/react-sw-update-tips

properties

NameTypeRequiredDefaultDescription
classNamestringfalse-The extended className for component.
textunionfalse'↺ 有新版本更新啦,点击刷新'Tips text.
valueboolfalsefalseDefault value.
hiddenboolfalsefalseThe html hidden status.
onChangefuncfalse-The change handler.

usage

  1. import css

    @import "~@jswork/react-sw-update-tips/dist/style.scss";
    
    // customize your styles:
    $react-sw-update-tips-options: ()
  2. import js

    import NxOfflineSw from '@jswork/next-offline-sw';
    import React from 'react';
    import ReactDOM from 'react-dom';
    import ReactSwUpdateTips from '@jswork/react-sw-update-tips';
    import './assets/style.scss';
    
    class App extends React.Component {
      state = {
        hasUpdate: true
      };
    
      componentDidMount() {
        this.installSw();
      }
    
      installSw() {
        NxOfflineSw.install({
          onUpdateReady: function () {
            // this.setState({ hasUpdate: false });
            console.log('SW Event:', 'onUpdateReady');
          }
        });
      }
    
      render() {
        return (
          <div className="app-container">
            <ReactSwUpdateTips value={this.state.hasUpdate} />
          </div>
        );
      }
    }
    
    ReactDOM.render(<App />, document.getElementById('app'));

documentation

license

Code released under the MIT license.