React-Handler
A react-component for handling typical react/redux-states (loading, error, ...)
Usage
npm install react-handler --save
Handler
;; // ... state = loading: true error: '' articles: thispropsarticles ; // ... { return <Handler loading=thisstateloading errorMessage=thisstateerror loadingMessage="loading..." emptyMessage="0 Articles found" checkedProperty=thisstatearticles > <ArticleList articles=thisstatearticles /> </Handler> ; }
Configuration
- All params from Subhandler´s will be available in Handler (Messages will only be prefixed)
- showComponentWhileLoading - will show you´re Component while your data is loading (default: true)
Sub-Handler
Loading
;; // ... state = loading: true articles: thispropsarticles ; // ... { return <LoadingHandler loading=thisstateloading> <ArticleList articles=thisstatearticles /> </LoadingHandler> ; }
Configuration:
- LoadingComponent - Define your own LoadingComponent
- loading - Is loading in process
- message - Define your own Loading-Message
Error
;; // ... state = error: '' articles: thispropsarticles ; // ... { return <ErrorHandler message=thisstateerror> <ArticleList articles=thisstatearticles /> </ErrorHandler> ; }
Configuration:
- ErrorComponent - Define your own ErrorComponent
- message - Error-Message, also used for error-check
Empty
;; // ... state = articles: thispropsarticles ; // ... { return <EmptyHandler message="0 Articles found." checkedProperty=thisstatearticles> <ArticleList articles=thisstatearticles /> </EmptyHandler> ; }
Configuration:
- EmptyComponent - Define your own EmptyComponent
- checkedProperty - Property, which should not be empty
- message - Define your Empty-Message
ErrorEmptyHandler
;; // ... state = articles: thispropsarticles error: '' ; // ... { return <ErrorEmptyHandler errorMessage=thisstateerror emptyMessage="0 Articles found." checkedProperty=thisstatearticles > <ArticleList articles=thisstatearticles /> </ErrorEmptyHandler> ; }
Configuration:
- Combines both Configuration´s from EmptyHandler and ErrorHandler, the messages will only be prefixed.
Contributing
- Fork and clone this repository
- Make your changes
- Check tests and linter
- Commit & push your changes
- Create pull request
License
Copyright (c) 2016-2017 Chris Helgert. See License for details.