- 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,
});
- C語言程序設(shè)計(jì)教程
- Building a RESTful Web Service with Spring
- Cross-platform Desktop Application Development:Electron,Node,NW.js,and React
- Java加密與解密的藝術(shù)(第2版)
- 秒懂設(shè)計(jì)模式
- 信息技術(shù)應(yīng)用基礎(chǔ)
- 前端HTML+CSS修煉之道(視頻同步+直播)
- HTML5與CSS3基礎(chǔ)教程(第8版)
- Python算法指南:程序員經(jīng)典算法分析與實(shí)現(xiàn)
- 常用工具軟件立體化教程(微課版)
- Mastering Git
- Visual Studio Code 權(quán)威指南
- Java7程序設(shè)計(jì)入門經(jīng)典
- C語言程序設(shè)計(jì)
- Mastering Leap Motion