Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax Lookup @react.component decorator #202

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions misc_docs/syntax/decorator_react_component.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
id: "react-component-decorator"
keywords: ["react", "component", "decorator"]
name: "@react.component"
summary: "This is the `@react.component` decorator."
category: "decorators"
---

The `@react.component` decorator is used to annotate functions that are [ReasonReact](https://reasonml.github.io/reason-react/en/) components.
kevanstannard marked this conversation as resolved.
Show resolved Hide resolved

You will need this decorator whenever you want to use a ReScript / React component in ReScript JSX expressions.

**Note:** The `@react.component` decorator requires the [react-jsx config](/docs/manual/latest/build-configuration#reason-refmt-old) to be set in your `bsconfig.json` to enable the required React transformations.

### Example

<CodeTab labels={["ReScript", "JS Output"]}>

```res
@react.component
let make = (~name) => {
<button> {ReasonReact.string("Hello " ++ name ++ "!")} </button>
}
```

```js
var React = require("react");

function MyComponent(Props) {
var name = Props.name;
return React.createElement("button", undefined, "Hello " + name + "!");
}

var make = MyComponent;
```

</CodeTab>

### References

* [ReasonReact Components](https://reasonml.github.io/reason-react/docs/en/components)