Comments (5)
Hey! See the message in the doc. Is your project using true es6 or simulated es6 through webpack/babel? The advice only applies to the latter
from bucklescript.github.io.
Hi, I generated the project with https://github.com/reasonml-community/reason-scripts. That should be simulated es6, right?
from bucklescript.github.io.
cc @rrdelaney ^ does reason-script/cra detect es6 support and use the real one?
from bucklescript.github.io.
It looks like reason-scripts uses webpack 3, which I think supports native ES Modules. Is the library published as ES6 on npm though? From what I can tell react-spinner
uses a UMD setup, so it should be able to be required using either of the above methods.
from bucklescript.github.io.
@chenglou @rrdelaney I ran into something similar when trying to bind react-native-splash-screen.
In my .js component this is easy:
import SplashScreen from 'react-native-splash-screen';
...
componentDidMount() {
SplashScreen.hide();
}
I tried writing the equivalent in my Reason component (after reading the docs):
[@bs.module "react-native-splash-screen"]
external hide : unit => unit = "hide";
...
didMount: _self => hide(),
This transpiles to:
var ReactNativeSplashScreen = require("react-native-splash-screen");
ReactNativeSplashScreen.hide();
Which should work BUT react-native-splash-screen
exports default
meaning the above hide
is actually undefined. If it transpiled to ReactNativeSplashScreen.default.hide()
it works fine.
I tried to Reason my way through this with:
type splash = {hide: unit => unit};
[@bs.module "react-native-splash-screen"]
external splashScreen : splash = "default";
...
didMount: _self => splashScreen.hide(),
but that transpiles to:
var ReactNativeSplashScreen = require("react-native-splash-screen");
...
/* didMount */(function () {
return Curry._1(ReactNativeSplashScreen.default[/* hide */0], /* () */0);
})
which crashes complaining about undefined at 0.
I hassled the people on the Reason discord, they provided me with this solution:
[@bs.module "react-native-splash-screen"] [@bs.scope "default"]
external hide : unit => unit = "hide";
...
hide();
Which totally works!
Maybe this will help you too? I think it should be added to the docs but unsure if the proper place is in the Reason docs or the BuckleScript docs..
from bucklescript.github.io.
Related Issues (20)
- Copy over the setup from reasonml.github.io
- some suggestions HOT 3
- Fix typo Js.Json.object_ HOT 1
- Algolia still wrong HOT 1
- object.md out of date, maybe? HOT 1
- Reason snippets don't hide HOT 1
- Add more languages HOT 1
- Document using bsc to generate interface file
- Explain Bucklescript's name mangling rule
- 6 broken links and a couple of other issues HOT 2
- Upstream glennsl's stuff HOT 1
- Add prettier to ensure consistent formatting HOT 3
- bs.raw Example produces compiler warnings HOT 1
- Fix documentation HOT 1
- Doc change to make FFI bindings easier to learn
- It would be interesting to have an .epub version of the docs. maybe we can use pandoc to generate something appropriate from the .md files.
- Toggling REASON/OCAML doesn't seem to work HOT 1
- Mention `[@@bs.get]` on page about objects
- https://www.rust-lang.org/en-US/whitepapers.html for BuckleScript
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bucklescript.github.io.