簡體   English   中英

如何在MeteorJS / React中將對象存儲在變量中以稍后返回?

[英]How can I store an object in MeteorJS/React in a variable to return later?

這段代碼在名為“塊”的組件的底部。

export default theBlockContainer = createContainer(({ params }) => {

  return {
      voteStatus:Meteor.user()['listofvoted'],
    }

}, Block);

上面的代碼很完美,但是我想對其進行重構。

我有什么辦法可以將“ voteStatus:Meteor.user()['listofvoted']”位存儲在return語句之前的變量中,以便return語句只需要返回變量?

理想情況是這樣的...

export default theBlockContainer = createContainer(({ params }) => {
  let temp = voteStatus:Meteor.user()['listofvoted'],
  return {
      temp;
    }

}, Block);

我認為我缺少基本的東西,因為這似乎是一項直接的任務,但是我已經嘗試了無數次,並且以同樣多種方式嘗試過這種嘗試,但只收到了編譯器錯誤。

export default theBlockContainer = createContainer(({ params }) => {
  this.setState({value: Meteor.user()['listofvoted']});
  return {
      this.state.value;
    }
}, Block);

該代碼將為您服務。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM