An open API service indexing awesome lists of open source software.

https://github.com/bernalrs/bs-react-notification-system

Reasonml binding for react-notification-system
https://github.com/bernalrs/bs-react-notification-system

Last synced: about 2 months ago
JSON representation

Reasonml binding for react-notification-system

Awesome Lists containing this project

README

        

# Reason bindings for react-notification-system

[![npm](https://img.shields.io/npm/v/bs-react-notification-system.svg)](https://www.npmjs.com/package/bs-react-notification-system)

[Reason](https://reasonml.github.io/) bindings for [react-notification-system](https://github.com/igorprado/react-notification-system).

## Status

🚧 This is a WIP, not everything is supported yet. 🚧

Feel free to create an issue or PR if you find anything missing.

## Installation

```
yarn add bs-react-notification-system
yarn add [email protected]
```

Then add `bs-react-notification-system` to `bs-dev-dependencies` in your `bsconfig.json`:

```json
{
...
"bs-dev-dependencies": ["bs-react-notification-system"]
}
```

## Usage

```reason
type action =
| AddNotification(string);

type state = {
_notificationSystem: ref(option(ReasonReact.reactRef)),
};

let setNotificationSystemRef = (notificationRef, {ReasonReact.state}) =>
state._notificationSystem := Js.Nullable.to_opt(notificationRef) ;

let component = ReasonReact.reducerComponent("Notifications");

let addNotification = (message, state) => {
switch state._notificationSystem^ {
| None => ()
| Some(r) => ReasonReact.refToJsObj(r)##addNotification({"message": message, "level": "success"});
}
};

let make = (_children) => {
...component,
initialState: () => {_notificationSystem: ref(None) },
reducer: (action, state) =>
switch action {
| AddNotification(message) => ReasonReact.SideEffects(((_) => addNotification(message, state)))
},
render: ({handle, reduce}) => (



AddNotification("Hello"))) > (ReasonReact.stringToElement("Click"))

)
};
```

## Bindings

- [x] NotificationSystem