Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/aminnairi/react-mui-snackbar

React Material UI's Snackbar provider & utilities written in TypeScript.
https://github.com/aminnairi/react-mui-snackbar

Last synced: about 5 hours ago
JSON representation

React Material UI's Snackbar provider & utilities written in TypeScript.

Awesome Lists containing this project

README

        

# react-mui-snackbar

React Material UI's Snackbar provider & utilities written in TypeScript.

## Requirements

- [Node](https://nodejs.org/)
- [NPM](https://www.npmjs.com/)
- [React](https://www.npmjs.com/package/react)
- [ReactDOM](https://www.npmjs.com/package/react-dom)
- [Material UI](https://www.npmjs.com/package/@mui/material)

## Installation

```bash
npm install @aminnairi/react-mui-snackbar
```

## Usage

```tsx
// ./src/index.jsx

import React, { StrictMode } from "react"
import { createRoot } from "react-dom/client"
import { SnackbarContextProvider } from "@aminnairi/react-mui-snackbar"
import { App } from "./components/app"

const rootElement = document.getElementById("root")

if (!rootElement) {
throw new Error("Root element not found")
}

const root = createRoot()

root.render(





)
```

```tsx
// ./src/components/app.jsx

import React, { Fragment, useEffect } from "react"
import { useSnackbarContext } from "@aminnairi/react-mui-snackbar"
import { Button } from "@mui/material"

export const App = () => {
const {
openSnackbar,
closeSnackbar,
setSnackbarSeverity,
setSnackbarMessage
} = useSnackbarContext()

useEffect(() => {
setSnackbarSeverity("success")
setSnackbarMessage("Hello, world!")
}, [])

return (

Open Snackbar
Close Snackbar

)
}
```