1.0.3 • Published 4 years ago

@jswork/react-static-container v1.0.3

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

react-static-container

Static container for react.

version license size download

installation

npm install -S @jswork/react-static-container

properties

NameTypeRequiredDefaultDescription
asanyfalseReact.FragmentThe static node name.
depsarrayfalse[]The deps of the component.
dynamicboolfalsefalseThe default should update.

usage

  1. import css

    @import "~@jswork/boilerplate-react-component/dist/style.css";
    
    // or use sass
    @import "~@jswork/boilerplate-react-component/dist/style.scss";
    
    // customize your styles:
    $boilerplate-react-component-options: ()
  2. import js

    import React, { useState } from 'react';
    import ReactStaticContainer from '../@jswork/boilerplate-react-component';
    import styled from 'styled-components';
    
    const Container = styled.div`
      width: 80%;
      margin: 30px auto 0;
    `;
    
    export default (props: any) => {
      const [count, setCount] = useState(10);
      const [id, setId] = useState(0);
      return (
        <Container>
          <button onClick={(e) => setCount(count + 1)}>Change Counter</button>
          <button onClick={(e) => setId(Date.now())}>Change Id</button>
          <p>
            I can not change.(except the first time.)
            <ReactStaticContainer>{count}</ReactStaticContainer>
          </p>
          <p>
            I can change.(Because i have deps changed.)
            <ReactStaticContainer deps={[id]}>{count}</ReactStaticContainer>
          </p>
          <p>
            <strong>I can change {count}</strong>
          </p>
        </Container>
      );
    };

license

Code released under the MIT license.