Code Monkey home page Code Monkey logo

react-redux-ui-state's People

Contributors

adamcbrewer avatar jasonmorita avatar krishnasaga avatar mlcohen avatar patrickshaughnessy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-redux-ui-state's Issues

Persist state?

Could this be a consideration? Either by default or as an option?

It would mean not resetting the state when a component is unmounted?

Updating uiState triggers re-render of separate components

Good day!

I'm facing an issue where different uiState-wrapped components trigger a re-render whenever the uiState state object is updated. This makes sense, since we're using immutablity-helper to return a new copy of the uiState object with the updated sub-states, but the trouble is that I end up with the re-rendering of completely separate components that happen to share in uiState, affecting the performance of my application.

For example, if we have two separate Component1 and Component2:

class Component1 extends React.Component {
  constructor(props) {
    super(props);
  }
  onDivClick = () => {
    this.props.setUiState({ uiC1Active: !this.props.uiC1Active  })
  }
  render() {
    return (
      <div onClick={this.onDivClick}>
        <h1> Component 1</h1>
      </div>
    );
  }
}
const uiStateConfig = {
    name: () => `Component1`,
    state: (props) => ({
        uiC1Prop: 'uiProp',
    }),
};

export default connectedComponent1 = compose(
  uiState(uiStateConfig),
)(Component1);

And Component2:

class Component2 extends React.Component {
  constructor(props) {
    super(props);
  }
  onDivClick = () => {
    this.props.setUiState({ uiC2Active: !this.props.uiC2Active  })
  }
  render() {
    return (
      <div onClick={this.onDivClick}>
        <h1> Component 2 </h1>
      </div>
    );
  }
}
const uiStateConfig = {
    name: () => `Component2`,
    state: (props) => ({
        uiC2Prop: 'uiProp',
    }),
};
export default connectedComponent2 = compose(
  uiState(uiStateConfig),
)(Component2);

Clicking on Component1's div will trigger a re-render for Component1 as well as Component2, and in fact any other components that happen to have their own uiState slice.

Is this by design, and is there a way get around this?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.