我有新的反应。所以对我来说,当一些反应状态得到更新。调用返回函数中的所有其他状态更改事件。
例如:
我的国家:
this.setState({
feeds : topics
})
所以我正在使用child_added事件监听firebase数据库,并使用以下代码更新我的Feed状态,
<HomeBar avatar={this.state.avatar} />
它适用于Feed组件。但是与其他州相关的所有其他组件都会再次被调用,
<Card className={"middleContainer"}>
{this.getChatBox(this.state.activechat)}
</Card>
和
//Code for Writing to File. Client Object is created through user input in GUI
try{
Address a1=new Address(Integer.parseInt(houseNumberField.getText()),Integer.parseInt(streetNumberField.getText()),cityField.getText(),provinceField.getText());
Client c1=new Client(firstNameField.getText(),lastNameField.getText(),emailField.getText(),passwordField.getText(),Float.parseFloat(phoneField.getText()),Float.parseFloat(CNICField.getText()),a1);
OutputStream out=null;
ObjectOutputStream outputStream=null;
FileOutputStream fileOut=null;
try
{
fileOut=new FileOutputStream("ClientList.ser",true);
outputStream=new ObjectOutputStream(fileOut);
outputStream.writeObject(c1);
JOptionPane.showMessageDialog (null,"record saved","Information",JOptionPane.INFORMATION_MESSAGE);
}
catch(IOException e)
{
System.out.println("Error while opening file");
}
finally {
try {
if(outputStream != null && fileOut!=null) {
outputStream.close();
fileOut.close();
}
}
catch (IOException e)
{
System.out.println("IO Exception while closing file");
}
}
那么我该如何解决这个问题:(
Home和HomeBar的Pastebin
答案 0 :(得分:0)
默认情况下,只要组件变脏(其状态已更改),就会重新呈现该组件及其子组件。 见 - &gt; https://stackoverflow.com/a/24719289/2092817