0
class SurveyQuestion extends React.Component {
  constructor(props) {
    model.onComplete.add(function(result) {
      return <TestEmpty message="test" />;
    }
  });
}

I am new to react, apologize if this is basic question, Is there any chance that if I could return component inside the constructor function, please? When it is completed then return component.

I tried with my code, it is not working and no error message.

4
  • The code is correct, basically. The question is what is model and what is model.onComplete? And also - why you need the result in the function if you don't have any usage of that variable? Commented Sep 19, 2017 at 15:03
  • surveyjs.io/Examples/Library/… this third party library called SurveyJs, it has a method called onComplete. Commented Sep 19, 2017 at 15:05
  • No one will go an check this lib. You should be able to provide the relevant information as part of your question. What add should receive? And again - what is model? Commented Sep 19, 2017 at 15:07
  • You should not be rendering a component inside the constructor. Render is it's own method and should go outside of the constructor. Commented Sep 19, 2017 at 15:09

1 Answer 1

4
  1. you cannot return component from constructor.
  2. In your case you use statefull component SurveyQuestion. In this case before to use it you need instantiate a parent class Component which you inherit(extands) by passing a super(props) invoking parent class constructor first inside of your component constructor.
  3. In statefull component you can rewrite your function beyond the constructor using this.state option of React if you want to track a change a statement of the properties by event(put it inside of simple eventHandler)
  4. Statefull component expects from you a render method. So your return method will be inside of it. And of course don't forget about import statement anywhere you need it.;) P.S.
  5. You could use a stateless component either. Which could be more convinient for you. Check it out here https://facebook.github.io/react/docs/components-and-props.html
Sign up to request clarification or add additional context in comments.

Comments

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.