til/ReScript: Adding a third-party library
Sometimes we want to include a library that extends our code. To add a third-party library to our ReScript code we use npm
as we would in a JavaScript project, but after installing we need to adjust our ReScript configuration to include the new code.
We start by installing the library using npm
or yarn
. For this example, I'll be using @opendevtools/rescript-telefonnummer
.
npm install --save @opendevtools/rescript-telefonnummer
After the installation is complete we need to add the library name in our bsconfig.json
in the bs-dependencies
array.
// bsconfig.json
{
...
"bs-dependencies": [
...,
"@opendevtools/rescript-telefonnummer"
]
}
After saving, the compiler will pick up that a change has been made in the configuration and build the library. We're now ready to start using the library in our code.
ReScript series
- ReScript: Creating a React component
- ReScript: Using React components
- ReScript: Adding a third-party library
- ReScript: Using useState in rescript-react
- ReScript: Using useReducer in rescript-react
- ReScript: Adding new actions to an existing useReducer
- ReScript: Using useContext in rescript-react
- ReScript: Connect to localStorage using FFI and functors
- ReScript: FFI basics in React
- how I add Tailwind to my ReScript projects