A simple example:
import { RSL_LOAD } from 'redux-script-loader';
dispatch({
type: RSL_LOAD,
payload: 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-beta1/jquery.min.js',
success: 'LOAD_SUCCESS',
fail: 'LOAD_FAIL',
});To install from npm:
$ npm install --save redux-script-loader
Then to configure with your redux store:
import { createStore, applyMiddleware } from 'redux';
import { loaderMiddleware } from 'redux-script-loader';
import reducer from './reducers';
const store = createStore(reducer, applyMiddleware(loaderMiddleware(document)));A symbol indicating that the action should be handled by the redux-script-loader middleware.
Returns a redux-compatible middleware. Must be initialised with the document object.
Must be RSL_LOAD imported from the redux-script-loader package.
The URL from which to load the script. Will be used as the src attribute of the script tag.
Action to dispatch when appending the script tag to the document. Can either be a string, or a Flux standard action.
Action to dispatch when the appended script tag finishes loading. Equivalent to the load event on the script element.
Action to dispatch when the appended script tag fails to load. Equivalent to the error event on the script element.