Skip to content

Commit d600e02

Browse files
authored
Merge pull request #202 from kevanstannard/syntax-lookup-react-component-decorator
Syntax Lookup @react.component decorator
2 parents 31f2ad6 + 6bfb9b9 commit d600e02

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
id: "react-component-decorator"
3+
keywords: ["react", "component", "decorator"]
4+
name: "@react.component"
5+
summary: "This is the `@react.component` decorator."
6+
category: "decorators"
7+
---
8+
9+
The `@react.component` decorator is used to annotate functions that are [ReasonReact](https://reasonml.github.io/reason-react/en/) components.
10+
11+
You will need this decorator whenever you want to use a ReScript / React component in ReScript JSX expressions.
12+
13+
**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.
14+
15+
### Example
16+
17+
<CodeTab labels={["ReScript", "JS Output"]}>
18+
19+
```res
20+
@react.component
21+
let make = (~name) => {
22+
<button> {ReasonReact.string("Hello " ++ name ++ "!")} </button>
23+
}
24+
```
25+
26+
```js
27+
var React = require("react");
28+
29+
function MyComponent(Props) {
30+
var name = Props.name;
31+
return React.createElement("button", undefined, "Hello " + name + "!");
32+
}
33+
34+
var make = MyComponent;
35+
```
36+
37+
</CodeTab>
38+
39+
### References
40+
41+
* [ReasonReact Components](https://reasonml.github.io/reason-react/docs/en/components)

0 commit comments

Comments
 (0)