-
Notifications
You must be signed in to change notification settings - Fork 71
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
Article about Feliz and Fable React #350
Open
isaacabraham
wants to merge
8
commits into
master
Choose a base branch
from
feliz-fablereact
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
553fa52
Article about Feliz and Fable React
isaacabraham 16818da
Code sample fixes
isaacabraham bb76f37
remove redundant `text [ Value...` code in setting p text
Larocceau 86a00f9
Showcase Html.p string overload
Larocceau 53864d7
simplify comment about interoperability of Fable.React and Feliz
Larocceau d59c989
make prop.children snippet a bit more compact
Larocceau c8e3c51
Merge remote-tracking branch 'origin/master' into feliz-fablereact
Larocceau 36377cc
consistent placement of comments
Larocceau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
In a nutshell Fable.React and Feliz are two F# libraries which perform a similar function: | ||
|
||
* Provide a typesafe F# wrapper to allow you to interact with React. | ||
* Provide a way to create your own wrappers around existing React components. | ||
* Provide a DSL for you to consume and create React wrappers in a consistent way. | ||
|
||
## DSL differences | ||
The main distinction between the two libraries is that Fable.React follows a layout as follows: | ||
|
||
```fsharp | ||
element [ prop; prop ] [ childElement; childElement ] | ||
``` | ||
|
||
For example: | ||
|
||
```fsharp | ||
h1 [ Style [ Color "Tomato" ] ] [ | ||
p [] [ str "Hello" ] // no props | ||
p [] [ str "Another paragraph" ] // no props | ||
h2 [ Style [ Color "Blue" ] ] [] // no child elements | ||
] | ||
``` | ||
|
||
In this example, `h1` is the "top level" element, with a single attribute and three children, two of which have their own children. | ||
|
||
Feliz adopts a different style, in which instead of an element having two lists, there is only one. The list directly contains *either* attributes *or* child elements, but not both: | ||
|
||
The above snippet would convert into Feliz as follows: | ||
|
||
```fsharp | ||
Html.h1 [ | ||
prop.style [ style.color "Tomato" ] | ||
prop.children [ | ||
Html.p [ prop.text "Hello" ] | ||
Html.p "Another paragraph" | ||
Html.h2 [ prop.style [ style.backgroundColor "Blue" ] ] | ||
] | ||
] | ||
``` | ||
|
||
The `prop.children` function is required when mixing and matching attributes and elements: | ||
|
||
```fsharp | ||
Html.h1 [ // this is fine - just props underneath h1 | ||
prop.style [ style.color "Tomato" ] | ||
prop.title "foo" | ||
] | ||
|
||
Html.h1 [ // fine - just elements underneath h1 | ||
Html.p [ prop.text "Hello" ] | ||
] | ||
|
||
Html.h1 [ // not fine - can't mix and match attributes and elements | ||
prop.style [ style.color "Tomato" ] | ||
Html.p [ prop.text "Hello" ] | ||
] | ||
|
||
Html.h1 [ // fine, adding props, and adding children using prop.children | ||
prop.style [ style.color "Tomato" ] | ||
prop.children [ Html.p [ prop.text "Hello" ] ] | ||
] | ||
``` | ||
|
||
## Guidance | ||
* Fable.React was created initially, whilst Feliz was developed some time later. | ||
* Feliz has better support for React interop and the majority of the community nowadays uses the Feliz DSL style for developing components. | ||
* Fable.React and Feliz can be mixed into your application if required (for progressive migration for example) | ||
|
||
|
||
* Also see [My journey with Feliz | A comparison between Fable.React and Feliz](https://github.com/Zaid-Ajaj/Feliz/issues/155). |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Mixed into" doesn't necessarily imply mixed together, so I'd make this clearer.