What I Googled Today (WIGT) #1

I need to get back to writing regularly. Ages ago I wiped all my blog posts so I could start fresh and then…didn’t. I figure the easiest way to get started is just start sharing what I have to google every day. It’ll help me build a habit, create a reference for Future Me, and serve as further evidence that being a software engineer is in part being a Professional Google Searcher. Here we go.

How to make comments in JSX?

Answer: When you’re inside a JSX block — so, for example, below a <div> and above a <button> — you use: {/* comments here/*}

Reference: Babel, JSX, and Build Steps – React (reactjs.org)

How I got here: I’m working through Epic React by Kent C. Dodds (which is great, by the way) and I needed to leave myself some notes. There are a lot of different opinions about how to comment your code and when, but when I’m learning something new on my own I’m very pro “comment directly in your file”. It helps me make sure I can explain what’s happening and gives me a reference when I come back and don’t remember what I was doing.

Why event prevent default?

Answer: Using event.preventDefault() keeps the browser from executing the default behavior of the event being triggered by a user’s actions (e.g. clicking on the submit button in a form). We commonly use it in forms so we can validate input in some way before submitting.


How I got here: Working on an exercise about forms in React, we needed to make an event handler. Using .preventDefault is something I’ve done plenty of times but had never bothered to look up to learn about how it works or why.

Use State Hook

Answer: Per the React docs: “Hooks are a new addition in React 16.8. They let you use state and other React features without writing a class,” and “useState is a Hook that lets you add React state to function components.”

Reference: Using the State Hook – React (reactjs.org)

How I got here: That’s it, that’s all I googled: “use state hook”. Hooks were mentioned in the exercise I was working on and I wanted to read more about the one we were using.