- Redux Quick Start Guide
- James Lee Tao Wei Suresh Kumar Mukhiya
- 224字
- 2021-07-02 12:40:30
Action creators
JavaScript functions that take some arguments and return actions are action creators. Let's look at an action creator function for adding a new doctor to the application:
function addNewDoctor(data) {
return {
type: ADD_NEW_DOCTOR_REQUEST,
data
};
}
Now, you can think of a function that you might need for deleting a record, as follows:
function deleteDoctor(identifier) {
return {
type: "DELETE_DOCTOR_REQUEST",
identifier
};
}
Before we move on to reducers, let's make one more action creator for authentication. Generally, to authenticate, we use an email and password. So, in order to authenticate (or deauthenticate) we need to define actions. Please note that the actions that we define will be used in our project for a hospital management system. Our action for authentication could look something like the following:
export const authenticate = (credentials) => ({
type: "AUTHENTICATE",
payload: credentials
});
export const deauthenticate = () => ({
type: "DEAUTHENTICATE"
});
Similarly, let's create action creators for registering a user. When we register a user, we are likely to have a request, a success, or a failure. Based on these three states, we can create the action creators, as follows:
export const onRegisterRequest = user => ({ type: REGISTER_REQUEST, user });
export const onRegisterSuccess = user => ({ type: REGISTER_SUCCESS, user });
export const onRegisterFailure = message => ({
type: REGISTER_FAILURE,
message,
});
- Learning Real-time Processing with Spark Streaming
- Visual C++串口通信開發(fā)入門與編程實(shí)踐
- C語言程序設(shè)計(jì)案例教程(第2版)
- Three.js開發(fā)指南:基于WebGL和HTML5在網(wǎng)頁(yè)上渲染3D圖形和動(dòng)畫(原書第3版)
- Mastering Entity Framework
- 跟老齊學(xué)Python:輕松入門
- Learning DHTMLX Suite UI
- Mastering JBoss Enterprise Application Platform 7
- 深入分布式緩存:從原理到實(shí)踐
- Raspberry Pi Home Automation with Arduino(Second Edition)
- Fast Data Processing with Spark(Second Edition)
- Java并發(fā)編程之美
- Kotlin Programming By Example
- Appcelerator Titanium:Patterns and Best Practices
- Instant Pygame for Python Game Development How-to