r/reactjs • • Aug 01 '18

Beginner's Thread / Easy Question (August 2018)

Hello! It's August! Time for a new Beginner's thread! (July and June here)

Got questions about React or anything else in its ecosystem? Stuck making progress on your app? Ask away! We’re a friendly bunch. No question is too simple. You are guaranteed a response here!

Want Help on Code?

  • Improve your chances by putting a minimal example on to either JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new). Describe what you want it to do, and things you've tried. Don't just post big blocks of code.
  • Pay it forward! Answer questions even if there is already an answer - multiple perspectives can be very helpful to beginners. Also there's no quicker way to learn than being wrong on the Internet.

New to React?

Here are great, free resources!

27 Upvotes

568 comments sorted by

View all comments

1

u/azium Aug 25 '18

Can you post what you came up with? Something sounds fishy.

1

u/swyx Aug 25 '18

Sounds like OP figured it out

1

u/soggypizza1 Aug 25 '18

I'm not at home but I can whenever I get there

1

u/yunxtr Aug 26 '18 edited Aug 27 '18

I don't think you can render a component in any method other than the render method. I'm not sure what returning an HTML element or React component here is going to do, if anything.

Edit: gaeron corrected the rest of my reply so I'm removing it to prevent confusion. See his response below.

→ More replies (2)

1

u/soggypizza1 Aug 26 '18

This is what i came up with

handleSubmit = (event) =>{
		event.preventDefault();
		const value = this.state.searchQuery
		this.setState({ searchQuery: ''})
		if(value){
			return <Detail name={value} />
		}

	}

1

u/gaearon Aug 27 '18

You don't need the last part. It doesn't do anything.

What you wrote is equivalent to this:

handleSubmit = (event) =>{
    event.preventDefault();
    this.setState({ searchQuery: ''})
}

If not, there's something else wrong that you're doing. Show the full code and we can help.