iamshaunjp / iamshaunjp/MERN-Stack-Tutorial

workoutsContext.js | TypeError: e is null | spread operator (...state)

Abierto
#12 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Sin datos de lenguaje
Estrellas
401
Forks
252
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

case 'CREATE_WORKOUTS' that returns workouts: [action.payload, ...state.workouts], raises " TypeError: e is null " when state.workouts is empty due to spread operator !

please add a if condition to avoid it , like below
case 'CREATE_WORKOUTS':
if (!state.workouts)
return {
workouts: [action.payload]
}
else
return {
workouts: [action.payload, ...state.workouts]
}

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

Open workoutsContext.js and locate the CREATE_WORKOUTS reducer case that spreads state.workouts. Check how it behaves when workouts is null or empty, then ensure the case returns the new workout without a TypeError and verify the reducer still preserves existing workouts.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
javascript
Área
frontend
Tipo de issue
Error
Dificultad
2/5
Tiempo estimado
1-3 horas
Estado de actividad
Estancado
Claridad
Bien especificado
Aptitud para principiantes
55/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.