DEV Community

mcwhopper63
mcwhopper63

Posted on

Use psuedocode to quickly learn React

when learning a new language/library, use #psuedocode to efficiently learn patterns/concepts/syntax

ex) below is a react component w an onClick handler

component {
callback arrow fxn
return (section
button with onClick{callback}
section
)}

this component will have a function that will fire when the event happens. the event is going to live on the button element. i'm using jsx syntax to inject my callback into the onClick method.

that said, i can code this out which will look like this:

const EventExamples = () => {
  const handleButtonClick = () => {
    alert('handle button click')
  }
  return (
    <section>
      <button onClick={handleButtonClick}>click me</button>
    </section>
  )
}
// code is from codingaddict's react course on youtube called react18. highly highly highly recommend
Enter fullscreen mode Exit fullscreen mode

Now I know the very basics of how to apply an event handler in react. nice!

and don't even get me started on the importance of psuedocode when solving algorithm problems ha

good luck all!

Top comments (0)