0.0.2 • Published 9 months ago

@vormadal/react-mui v0.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

vormadal/react-mui

This library contains a collection of hooks and components that I have found useful in my React projects.

Installation

Using npm

npm install @vormadal/react-mui

This library is intended to be used with the following libraries:

  1. react-router-dom
  2. @mui/material
  3. @mui/icons-material
  4. @emotion/react
  5. @emotion/styles

Components

Toaster

Loading

The <Loading /> component is used when you want to show a spinner while data is loading. The component works very well with the useData hook where the hook values can be forwarded to the <Loading /> component.
As long as there is no data the children will not be rendered. This way you don't have to check if data is defined or not.

Example

function MyComponent(){
    // result is an object containing 'loading', 'data' and 'error'
    const [result] = useData(() => /* make api call and return response */)
    return (<Loading {...result}>
        {/* data is the content of the value returned from the function passed to the useData hook */}
        {(data) => <div>{data.id}</div>}
      </Loading>)
}

Props

NameTypeDescriptiondefaultrequired
loadingbooleanIf true and data has no value a spinner is shownfalseno
errorstringShows an alert containing this error message''no
dataanythe data which will be passed to the children function when loading is completeundefinedno
showReloadsbooleanIf true the spinner will be shown everytime loading is true.falseno
retryfunctionIf specified, the alert will show a retry button which when clicked will run this functionundefinedno
childrenfunctionA function which returns the child elements to be rendered. The data will be passed as argument. This function will only be called when data contains dataundefinedno

Navigation

ProtectedRoute

Hooks

useData

useRequest

useToast

Jest references

Jest getting started

Jest config when using typescript (also use babel) https://kulshekhar.github.io/ts-jest/docs/getting-started/installation/#jest-config-file

0.0.2

9 months ago

0.0.1-alpha.5

9 months ago

0.0.1-alpha.4

9 months ago

0.0.1-alpha.3

9 months ago

0.0.1-alpha.2

9 months ago

0.0.1-alpha

9 months ago