How to integrate create-react-app
with PureScript
This example is a React application containing a PureScript component.
npm install
npm start
Either follow these steps or clone/fork this example repository.
npx create-react-app create-react-app-purescript --template typescript
Follow instructions to use craco
to overwrite parts of the create-react-app
configuration
https://github.com/gsoft-inc/craco/blob/master/packages/craco/README.md#installation
Extend craco configuration to use craco-purescript-loader
https://github.com/andys8/craco-purescript-loader
Install PureScript (compiler) and initialize spago (package manager)
npm install purescript spago --save-dev
npx spago init
Add npm script in package.json
and install dependencies with npm install
{
"postinstall": "spago build --deps-only"
}
This example is using react-basic
and react-basic-hooks
npx spago install react-basic react-basic-dom react-basic-hooks
- Add a PureScript component:
Counter.ps
- Allow module import in TS:
purescript-module.d.ts
- Import the component and use it:
App.tsx
import { mkCounter as Counter } from "./Counter.purs";
// ...
function App() {
return <Counter />;
}