0

I'm new to react. So for me when some react states get updated. All other state change event inside my return function gets called.

For example :

My State :

  state = {
    isLogined  : false,
    redirect: false,
    username: "",
    avatar : '',
    name : '',
    messages : [],
    feeds : [],
    activechat : {},
    currentRoom : '',
  }

So I'm listening a firebase database with child_added event and updating my feeds state by using the following code,

this.setState({
            feeds : topics
          })

It works fine for the feeds component. But all other component associated with other states are getting called again,

  <HomeBar avatar={this.state.avatar} />

and

<Card className={"middleContainer"}>
                {this.getChatBox(this.state.activechat)}
          </Card>

So how can i fix that :(

Pastebin for Home and HomeBar

https://pastebin.com/R4G2YCmY

Bucky
  • 1,116
  • 2
  • 18
  • 34

1 Answers1

0

By default, whenever a component is dirty (its state changed), that component and its children are re-rendered. See -> https://stackoverflow.com/a/24719289/2092817