rescript-association / rescript-lang.org

Official documentation website for the ReScript programming language
https://rescript-lang.org
MIT License
1.85k stars 246 forks source link

Add page about React.memo #889

Closed nojaf closed 3 months ago

nojaf commented 3 months ago

A lot of text comes from https://react.dev/reference/react/memo#memo. The important thing for me is the arePropsEqual example. Let me know if you like to see anything different.

vercel[bot] commented 3 months ago

@nojaf is attempting to deploy a commit to the ReScript Association Team on Vercel.

A member of the Team first needs to authorize it.

nojaf commented 3 months ago

@fhammerschmidt any suggestions?

nojaf commented 3 months ago

(Also, apologies for my impatience 😅)

fhammerschmidt commented 3 months ago

I think the arePropsEqual example can be simplified by shadowing the make function:

@react.component
let make = (~disabled, ~onClick) => {
  <button
    disabled={disabled}
    onClick={ev => ev->JsxEvent.Mouse.preventDefault->onClick}>
    {React.string("My button")}
  </button>
}

let make = React.memoCustomCompareProps(make, (p1, p2) =>
  p1.disabled == p2.disabled
)

Playground Link no explicit typing of props needed either, but I never used that personally.

nojaf commented 3 months ago

Oh that does seem simpler. My original example was based on https://forum.rescript-lang.org/t/looking-for-a-react-memo-example/1144/12?u=nojaf

I'll revisit the docs.

fhammerschmidt commented 3 months ago

Nice work!