bs-react-notification-system
v0.0.6
Published
Reason bindings for react-notification-system
Downloads
4
Maintainers
Readme
Reason bindings for react-notification-system
Reason bindings for 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
:
{
...
"bs-dev-dependencies": ["bs-react-notification-system"]
}
Usage
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}) => (
<div>
<ReactNotificationSystem ref=(handle(setNotificationSystemRef)) />
<button onClick=(reduce( (_) => AddNotification("Hello"))) > (ReasonReact.stringToElement("Click")) </button>
</div>
)
};
Bindings
- [x] NotificationSystem