Skip to Content
Build a Frontend Web Framework (From Scratch)
book

Build a Frontend Web Framework (From Scratch)

by Angel Sola
May 2024
Beginner to intermediate
384 pages
9h 29m
English
Manning Publications
Content preview from Build a Frontend Web Framework (From Scratch)

10 Component methods

This chapter covers

  • Implementing component methods to handle events
  • Binding a method’s context to the component
  • Passing the host component reference to mount and patch functions

What happens when you’re handling an event in a component that requires a couple of lines of code? One-liners, like this one, look fine inside the virtual Document Object Model (DOM) definition:

render() {
  const { count } = this.state

  return hFragment([
    h(
      'button',
      { on: { click: () => this.updateState({ count: count - 1 }) }}    #1
      ['Decrement']
    ),
    h('span', {},  [count]),
    h(
      'button',
      { on: { click: () => this.updateState({ count: count + 1 }) }}    #2
      ['Increment']
    )
  ])
}
#1 Handles the click event by decrementing the count #2 Handles the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

React - The Complete Guide (Includes Hooks, React Router, and Redux) - Second Edition

React - The Complete Guide (Includes Hooks, React Router, and Redux) - Second Edition

Academind by Maximilian Schwarzmüller GmbH
Full Stack Testing

Full Stack Testing

Gayathri Mohan

Publisher Resources

ISBN: 9781633438064Supplemental ContentPublisher SupportOtherPublisher WebsiteSupplemental ContentPurchase Link