English 中文(简体)
未更新的国家
原标题:React setState in class component not updating state

Good day; I m in need of assistance with the following problem:

反应类别组成部分(编号React.Component)暴露了将其置于指挥状态的方法。 我知道,用推进剂处理这一构成部分可能解决这个问题,但这一公开方法对我的具体设想极为有益,我很不愿意放弃。

The method looks like this:

public setContent = (newDoc: IDocsEntry) => {
    console.log( Updating with , newDoc);
    this.setState(() => ({doc: newDoc}), () => console.log(this.state.doc));
  };

我也进行了审判。

public setContent = (newDoc: IDocsEntry) => {
    console.log( Updating with , doc);
    this.setState(() => ({newDoc: {id: doc.id, path: doc.path, title: doc.title, content: doc.content}}), () => console.log(this.state.doc));
  };

The issue is as following:

  • on initially setting this state using this method, everything works as expected
  • when I then close this component (it lives in a modal), do something else and then try to update the state using this method, it simply does not update

在我的ole志中,我可以看到,这一方法被称作是新的正确目标,但<条码>的<国家<>/代码>的提示只是从首次援引这一功能时就显示出了老状态。

问题回答

贵方认为什么,也许你们会认为自己有义务确定

  this.setContent = this.setContent.bind(this);




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签