Skip to content

Instantly share code, notes, and snippets.

@vadimkorr
Last active August 23, 2019 14:37
Show Gist options
  • Save vadimkorr/79ae0a0a12d33cf1e374664eb495a29a to your computer and use it in GitHub Desktop.
Save vadimkorr/79ae0a0a12d33cf1e374664eb495a29a to your computer and use it in GitHub Desktop.
import React from "react";
import PropTypes from "prop-types";
import { View } from "react-native";
import { observer } from "mobx-react";
import { Notification } from "../Notification";
import { NotificationsStore, withNotifications } from "../store";
// 'observer' function turns component into reactive component
// component will be rerendered upon 'notifications' array change
const NotificationsInner = observer(props => {
const { store } = props;
return (
<React.Fragment>
{store.notifications.map((notification, index) => (
<View
key={notification.id}
style={{
marginTop: index !== 0 ? 15 : 0
}}
>
<Notification
type={notification.type}
title={notification.title}
message={notification.message}
onClosePress={() => {
store.remove(notification);
}}
/>
</View>
))}
</React.Fragment>
);
});
NotificationsInner.propTypes = {
store: PropTypes.instanceOf(NotificationsStore)
};
export const Notifications = withNotifications(NotificationsInner);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment