rescript-lang / rescript-lang/rescript-lang.org

Need better documentation on using ~_type in React

Open
#451 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
MDX
Stars
1.9k
Forks
260
Avg merge
3d 9h
Merged PRs (30d)
17

Description

I'm trying to bind to a React component that uses type=... and couldn't figure out how to do it. The correct answer - at least this works for me - is to use ~_type: string The documentation at https://rescript-lang.org/docs/react/latest/components-and-props#handling-invalid-prop-names-eg-keywords seems to say to use something like <input type_="text" /> with the underscore following the property name. This is exceptionally confusing. See related issue at https://forum.rescript-lang.org/t/how-to-bind-to-react-component-with-parameter-named-type/2471/3

I think the documentation around underscores on names and how to use keywords needs to be cleaned up. I also couldn't figure out why @as("type") didn't work.

@module("react-rewards") @react.component
external make: (
  ~ref: ReactDOM.domRef=?,
  ~children: React.element=?,
  ~config: config=?,
  ~_type: [#confetti | #emoji | #memphis]=?,
  unit,
) => React.element = "default"

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the “Handling invalid prop names (eg. keywords)” section at the linked React components-and-props documentation, then compare it with the reported react-rewards example and linked forum discussion. Clarify how underscore-prefixed names and @as("type") relate, and consider the issue complete when the documented syntax and keyword guidance are unambiguous.

Written by the indexing model from the issue text.

Assessment

Tech stack
react
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.