Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better dispatch action management #3

Open
mt-sette opened this issue Jul 26, 2024 · 0 comments
Open

Better dispatch action management #3

mt-sette opened this issue Jul 26, 2024 · 0 comments

Comments

@mt-sette
Copy link

To better manage dispatch actions and avoid copying and pasting in different parts of the project, you can create an action types utility file.

Create a file actionTypes.js:

// actionTypes.js
export const INCREMENT_COUNTER = 'INCREMENT_COUNTER';
export const DECREMENT_COUNTER = 'DECREMENT_COUNTER';

Update your counter-reducer.js:

// counter-reducer.js
import { INCREMENT_COUNTER, DECREMENT_COUNTER } from './actionTypes';

const initialState = {
    counter: 0,
};

const counterReducer = (state = initialState, action) => {
    switch (action.type) {
        case INCREMENT_COUNTER:
            return { ... }
                // rest of the code
};

export default counterReducer;
// Counter.jsx
import { INCREMENT_COUNTER, DECREMENT_COUNTER } from './actionTypes';

export const incrementCounter = () => ({
    type: INCREMENT_COUNTER,
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant