Skip to content

Commit f852e18

Browse files
Merge pull request #86 from DouglasConnect/master
Minor fixes and clarifications in the third part react components documentation
2 parents 8a25c62 + 0ceba61 commit f852e18

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ The basic steps when working with a Discriminated Union are:
2929

3030
Using yarn or npm, install the react component you want to use.
3131

32-
For example to use the [rc-progress React components](https://github.com/react-component/progress), run the following in your Fable project root:
32+
For example to use the [rc-progress](https://github.com/react-component/progress) React component which we'll be using in this tutorial, run the following command inside your Fable project root folder:
3333

3434
```bash
3535
yarn add rc-progress
@@ -71,13 +71,18 @@ There are several different ways to declare exports in Javascript (default impor
7171
In the example of rc-progress, to declare a `progressLine` creation function that imports the `Line` component from the library `rc-progress`, you would declare it as follows.
7272

7373
```fsharp
74+
open Fable.Core
75+
open Fable.React
76+
open Fable.Import.React
77+
open Fable.Core.JsInterop
78+
7479
let inline progressLine (props : ProgressProps list) (elems : ReactElement list) : ReactElement =
7580
ofImport "Line" "rc-progress" (keyValueList CaseRules.LowerFirst props) elems
7681
```
7782

78-
Note the `keyValueList` function that is used to convert the props of type `IProgressProps list` to a Javascript object where they key is the lower case name of the DU case identifier and the value is the field value of the DU (e.g. if the list that is passed into the function is `[Percent 40; StrokeColor "red"]`, the Javascript object that will be passed to the `props` of the `Line` react component would look like this: `{ percent: 40, strokeColor: "red" }`)
83+
The `keyValueList` function is used to convert the props of type `IProgressProps list` to a JavaScript object where the key is the lower case name of the discriminated union case identifier and the value is the field value of the discriminated union (e.g. if the list that is passed into the function is `[Percent 40; StrokeColor "red"]`, the Javascript object that will be passed to the `props` of the `Line` react component would look like this: `{ percent: 40, strokeColor: "red" }`)
7984

80-
In the docs of the [rc-progress React components](https://github.com/react-component/progress) the import styled used is a *member import*, so we use refer to the component member directly in the ofImport expression.
85+
In the docs of the [rc-progress](https://github.com/react-component/progress) React component the import style used is a *member import* (e.g. `import { Line, Circle } from 'rc-progress';`), so we refer to the component member `Line` directly in the ofImport expression.
8186

8287
### 4. Use the creation function in your view code
8388

@@ -89,7 +94,7 @@ To use the component in a [Fable-Elmish](https://fable-elmish.github.io/elmish/)
8994
let view (model : Model) (dispatch : Msg -> unit) =
9095
div
9196
[]
92-
[ progressLine [ percent model.currentProgress; strokeColor "red" ] [] ]
97+
[ progressLine [ Percent model.currentProgress; StrokeColor "red" ] [] ]
9398
```
9499

95100
## Importing using a Pojo (plain old JS object) record
@@ -120,7 +125,6 @@ open Fable.Core.JsInterop
120125
ofImport "Line" "rc-progress" (createObj ["strokeWidth" ==> 5]) []
121126
```
122127

123-
124128
## Edgecases
125129

126130
This documentation needs to be extended to cover [Higher Order Components](https://reactjs.org/docs/higher-order-components.html) and maybe [Context](https://reactjs.org/docs/context.html), [Fragments](https://reactjs.org/docs/fragments.html) etc. Contributions are welcome!

0 commit comments

Comments
 (0)