# request-state **Repository Path**: mirrors_mikaelbr/request-state ## Basic Information - **Project Name**: request-state - **Description**: Helps maintaining request state when using react-redux - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-08-09 - **Last Updated**: 2026-03-29 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README request-state === A simple immutable request-state container. Inpired by [RemoteDatajs](https://github.com/jackfranklin/remote-data-js). ### Install ```bash npm install request-state ``` **Motivation/Problem** Defining and displaying the state of a request is not that hard, but can be unnecessarily complicated. ```javascript const state = { loading: true, data: undefined } const state = { loading: false, data: undefined, error: undefined } // Updating this state is boring and might be repeted several places in our application const state = { loading: false, data: undefined, error: undefined, isSuccess: false, isError: false } ``` **Solution** The solution is to have a state for all request-state scenarios. `request-state` have four different states that can easily be updated and passed to your react-components: - IS_NOT_ASKED - request not started - IS_FETCHING - request started - SUCCESS - request success. We got some data - ERROR - the request went wrong ### Example Usage with a redux reducer `someReducer.js` ```javascript const RequestState = require('request-state'); const { FETCHING_DATA, DATA_RECEIVED, FAILED_TO_RECEIVE_DATA } = require('./actions'); const defaultState = new RequestState(); module.exports = (state = defaultState, action) => { switch (action.type) { case FETCHING_DATA: return state.fetching(); case DATA_RECEIVED: return state.success(action.data); // action.data = { name: 'Billy' } case FAILED_TO_RECEIVE_DATA: return state.error(action.err); // action.err = { message: 'could not get user' } default: return state.get(); } }; ``` `app.js` ```javascript const App = React.createClass({ componentDidMount: function() { dispatch(fetchUser('Billy')) }, render: function() { const request = this.props; if (request.isNotAsked()) return