Coder Social home page Coder Social logo

Comments (5)

chenglou avatar chenglou commented on June 20, 2024

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.

martinraison avatar martinraison commented on June 20, 2024

Hi, I generated the project with https://github.com/reasonml-community/reason-scripts. That should be simulated es6, right?

from bucklescript.github.io.

chenglou avatar chenglou commented on June 20, 2024

cc @rrdelaney ^ does reason-script/cra detect es6 support and use the real one?

from bucklescript.github.io.

rrdelaney avatar rrdelaney commented on June 20, 2024

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.

Angry-Potato avatar Angry-Potato commented on June 20, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.