Skip to content

Commit 590d8d4

Browse files
Add some more comment to using 3rd party components doc
1 parent f88fd42 commit 590d8d4

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

docs/using-third-party-react-components.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,37 @@ If the export is declard as a default export, then you would use ``"default"`` a
9292
Taking [react-native-qrcode-scanner](https://github.com/moaazsidat/react-native-qrcode-scanner) as an example:
9393

9494
To translate the example
95+
9596
```js
9697
import QRCodeScanner from 'react-native-qrcode-scanner';
9798
```
98-
you would declare your function like
99+
100+
you would declare your function like
99101

100102
```fsharp
101103
let inline qr_code_scanner (props : QRCodeScannerProps list) : ReactElement =
102104
ofImport "default" "react-native-qrcode-scanner" (keyValueList CaseRules.LowerFirst props) []
103105
```
104106

107+
#### Fields of imported items
108+
109+
Some React components must be instantiated as follows in JS:
110+
111+
```js
112+
import { Select } from 'react-select'
113+
let render = () => <Select.Creatable options={...} />
114+
```
115+
116+
In this case, you can also use `ofImport` to directly access the field of the imported item:
117+
118+
```fsharp
119+
// Import { Select } from "react-select" and then access the "Creatable" field
120+
ofImport "Select.Creatable" "react-select" myOptions []
121+
122+
// Also compatible with default imports
123+
ofImport "default.Creatable" "react-select" myOptions []
124+
```
125+
105126
#### Directly creating the element
106127

107128
If you already have a reference to the imported component, then you can also use ``createElement``.
@@ -113,6 +134,13 @@ let rnqs = importDefault "react-native-qrcode-scanner"
113134
createElement(rnqs, (keyValueList CaseRules.LowerFirst props), [])
114135
```
115136

137+
> Please note it's also OK to duplicate `ofImport` with same member and path. In this case, Fable will automatically group the imports.
138+
139+
```fsharp
140+
let foo1 = ofImport "default" "react-foo" { height = 25 } []
141+
let foo2 = ofImport "default" "react-foo" { height = 50 } []
142+
```
143+
116144
### 4. Use the creation function in your view code
117145

118146
The function you declared in step 2 now behaves just like any other React component function.

0 commit comments

Comments
 (0)