Skip to content

DOM manipulationΒ #40

@oliverjam

Description

@oliverjam

<li
onClick={event => {
setUser({ login, avatar_url });
event.target.classList.add("user-selected");
}}
>

Manually updating the DOM isn't very Reacty. JSX lets us conditionally set properties on elements, which means we can achieve this in a more declarative way:

<li
  className={user === login ? "user-selected" : null}
  onClick={event => {
    setUser({ login, avatar_url });
  }}
>

You would need to pass down the user as a prop in order to know that the state has changed though.

Oh also clickable things should probs be buttons, so you don't have to implement your own focus and keyboard handling πŸ™ƒ

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions