Skip to content

Instantly share code, notes, and snippets.

@Klerith
Last active November 8, 2024 21:52
Show Gist options
  • Save Klerith/060281f76f3b7f0a458e4b83b1fc0062 to your computer and use it in GitHub Desktop.
Save Klerith/060281f76f3b7f0a458e4b83b1fc0062 to your computer and use it in GitHub Desktop.
Cascaron para crear Redux Slices rápidamente
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;
@callejadev
Copy link

Muchas gracias Fer cari!

@migue-3
Copy link

migue-3 commented Mar 30, 2023

el mejor profe de udemy indiscutiblemente

@Mariperu
Copy link

Great! Thanks Fernando!

@ThorondorManwe
Copy link

Gracias Fernando sensei

@LuzJE
Copy link

LuzJE commented May 29, 2023

Gracias Fernando, ya quiero acabar el curso.

@JeanCornelio
Copy link

El mejor.

@madpixelchile
Copy link

Gracias Fernando!

@ramone02
Copy link

Gracias Profe Fernando!

@Daniels-123
Copy link

El mejor!!

@XkiritoxD
Copy link

Buen curso

@Quisutd3us
Copy link

Thxs Capo!!

@JulianLlanten8
Copy link

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!!

@LucianoChilean
Copy link

Gracias !!!!

@sebassg7
Copy link

Gracias por esta pieza de código Fernando, un abrazo!!!

@AbrahamVasquez
Copy link

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