Skip to content

Instantly share code, notes, and snippets.

@dwhitney
Last active March 5, 2022 12:54
Show Gist options
  • Star 24 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save dwhitney/e2a040432040607ae519fdf05cbc27ad to your computer and use it in GitHub Desktop.
Save dwhitney/e2a040432040607ae519fdf05cbc27ad to your computer and use it in GitHub Desktop.
Quick React Native with PureScript
  1. create-react-native-app purescript-app; cd purescript-app

  2. pulp init --force

  3. pulp build

  4. src/Main.js

var React = require("react");
var RN = require("react-native");

exports.text = function(props){
  return function(str){
    return React.createElement(RN.Text, props, str); 
  };
};
  1. src/Main.purs
module Main where

foreign import data ReactElement :: Type

foreign import text :: forall props. props -> String -> ReactElement

main :: ReactElement
main = text { style : { color : "green", fontSize : 50 } } "Hello from PureScript!" 
  1. ./App.js
import React from 'react';
import Main from "./output/Main";

export default class App extends React.Component {
  render() {
    return Main.main;
  }
}
  1. pulp build

  2. yarn start (create-react-native-app insists you use yarn, but npm may also work)

@lambdina
Copy link

lambdina commented Mar 5, 2022

Thank you very much for this quick and simple tutorial !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment