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

What the different between ReasonReact.string and React.string #406

Closed
fahmiirsyadk opened this issue Apr 24, 2019 · 4 comments
Closed

What the different between ReasonReact.string and React.string #406

fahmiirsyadk opened this issue Apr 24, 2019 · 4 comments

Comments

@fahmiirsyadk
Copy link

im new in ReasonReact , when i try the code from intro example

its using ReasonReact

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

but when i lookup on the component page, its using React instead ReasonReact

[@react.component]
let make = (~name) => {
  let (count, setCount) = React.useState(() => 0);

  <div>
    <p> {React.string(name ++ " clicked " ++ string_of_int(count) ++ " times")} </p>
    <button onClick={_ => setCount(_ => count + 1)}>
      {React.string("Click me")}
    </button>
  </div>
};

i'm super exited to learn ReasonReact <3

@banacorn
Copy link

banacorn commented Apr 24, 2019

Here's what I found from the source:

external string: string => element = "%identity";

external string: string => reactElement = "%identity";

I'm also curious about the difference between ReasonReact and the new React module .

EDIT: It seems like they are the same thing, from #360 (comment),

Just in case you didn’t notice, ReasonReact.reactElement is just an alias for React.element.

@fahmiirsyadk
Copy link
Author

ohh its look like they wanna migrate to the new API

The Record API is in feature-freeze. For the newest features and better support going forward, please consider migrating to the new function components.

@maxlibin
Copy link

maxlibin commented Apr 25, 2019

https://reasonml.github.io/reason-react/blog/

This release also makes use of a new React namespace for APIs for all of the code related to this new way of writing components. 
Some functions have been copied over (like React.string, React.array) and many are new (like hooks)!

@phated
Copy link
Contributor

phated commented Apr 25, 2019

There's no difference, it's just shorter and exists in the new namespace. The old APIs are in feature freeze so you probably just want to use React.string instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants