1

This piece of code is at the bottom of a component named 'Block'.

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

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

}, Block);

The code above works perfect, but I want to refactor it.

Is there any way for me to store the "voteStatus:Meteor.user()['listofvoted']" bit into a variable before the return statement, such that the return statement need to only return the variable?

Ideally something like this...

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

}, Block);

I think I'm missing something fundamental because it seems like a straight forward task, however I have tried this numerous times and in equally numerous ways but only to receive compiler errors.

1
  • Try: this.setState({ voteStatus: Meteor.user()['listofvoted'] }). This is using the state of your 'Block' component to store the variable. And then you should be able to return this.state.voteStatus; Commented Jul 29, 2016 at 10:51

1 Answer 1

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

This code will work for you..

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks this does work! However, is there a way to avoid using react states?
yes you can use store value in this.value = voteStatus:Meteor.user()['listofvoted'] and get by this.value
but make sure you go through this discussion which is more clear when to use state and when not : stackoverflow.com/questions/25207703/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.