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
- Host: GitHub
- URL: https://github.com/bernalrs/bs-react-notification-system
- Owner: bernalrs
- License: mit
- Created: 2017-12-29T08:32:57.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-01-12T11:17:51.000Z (over 7 years ago)
- Last Synced: 2025-03-14T22:39:17.164Z (3 months ago)
- Language: OCaml
- Size: 82 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Reason bindings for react-notification-system
[](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