Last active
November 8, 2024 21:52
-
-
Save Klerith/060281f76f3b7f0a458e4b83b1fc0062 to your computer and use it in GitHub Desktop.
Cascaron para crear Redux Slices rápidamente
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createSlice } from '@reduxjs/toolkit'; | |
export const templateSlice = createSlice({ | |
name: 'name', | |
initialState: { | |
counter: 10 | |
}, | |
reducers: { | |
increment: (state, /* action */ ) => { | |
//! https://react-redux.js.org/tutorials/quick-start | |
// Redux Toolkit allows us to write "mutating" logic in reducers. It | |
// doesn't actually mutate the state because it uses the Immer library, | |
// which detects changes to a "draft state" and produces a brand new | |
// immutable state based off those changes | |
state.counter += 1; | |
}, | |
} | |
}); | |
// Action creators are generated for each case reducer function | |
export const { increment } = templateSlice.actions; | |
Muchas gracias, me encanto esta parte.
Gracias, Profe
a mi no m funciona??
a mi no m funciona??
@fernandoCardona
¿Còmo que no te funciona?, es un template para que lo uses a tu conveniencia
Gracias!!!
Gracias fernando, excelente curso.
Thank u Fernando! Excelente Curso
👍 Se merece 🌟🌟🌟🌟🌟 estrellas, gracias por compartir tu aprendizaje.
Muchas gracias Fer cari!
el mejor profe de udemy indiscutiblemente
Great! Thanks Fernando!
Gracias Fernando sensei
Gracias Fernando, ya quiero acabar el curso.
El mejor.
Gracias Fernando!
Gracias Profe Fernando!
El mejor!!
Buen curso
Thxs Capo!!
Comparto mi snnipet, tiene el nombre del archivo incorporado automaticamente
{
"crear un slice de redux": {
key: "crear un slice de redux",
"prefix": "reduxSlice",
"body": [
"import { createSlice } from '@reduxjs/toolkit';",
"",
"export const ${1:${TM_FILENAME_BASE}} = createSlice({",
" //nombre del slice con el que se vincula al store",
" name: '${2:name}',",
" //declaracion del estado inicial de las variables",
" initialState: {",
" counter: 0,",
" },",
" //funciones que modifican el estado",
" reducers: {",
" ${3:increment}: (state) => {",
" state.counter += 1;",
" },",
" decrement: (state) => {",
" state.counter -= 1;",
" },",
" //incremeta por una cantidad dada",
" incrementByAmount: (state, action) => {",
" state.counter += action.payload;",
" },",
" },",
"});",
"",
"export const { increment, decrement, incrementByAmount } = ${1:${TM_FILENAME_BASE}}.actions;",
"",
],
"description": "Crear un slice de redux"
}
}
@Klerith Gracias!!
Gracias !!!!
Gracias por esta pieza de código Fernando, un abrazo!!!
Hay algo que este hombre no haga bien? ☑️☑️
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Muchas graciass Fernando