Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

166
Views
¿Cómo puedo solucionar el error Cómo solucionar el token u inesperado en JSON en la posición 0?

Tengo un error proveniente de mi código reductor de usuario. Esto es lo que he hecho.

 export const userReducer = ( state = localStorage.getItem('user') !== undefined ? JSON.parse(localStorage.getItem('user')) : null, action ) => { switch (action.type) { case 'LOGGED_IN_USER': return action.payload case 'LOGOUT': return action.payload default: return state } }

No sé si estoy declarando muy bien el estado. Siento que de ahí viene el problema.

He tratado de declarar mi estado como

 export const userReducer = ( state = localStorage.getItem('user') ? JSON.parse(localStorage.getItem('user')) : null, action ) => { switch (action.type) { case 'LOGGED_IN_USER': return action.payload case 'LOGOUT': return action.payload default: return state } }

Sigo recibiendo el mismo error y mi página no se carga. Muestra una pantalla en blanco, con el error en la consola.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Aquí hay un analizador JSON "seguro", que maneja una gran cantidad de JSON funky/roto/malo/corrupto:

 function jparse(str) { var result = null; try { result = JSON.parse(str) } catch (e) { // ignore } if (!result) { try { result = Function('return (' + str + ")")(); } catch(e){ // ignore } } return result; } console.log( jparse(null) ); // null console.log( jparse('{bob:"er"}') ); // {bob: 'er'} console.log( jparse('{\'bob\':"er"}') );// {bob: 'er'} console.log( jparse('{bob:}') ); // null console.log( jparse(0) ); // 0 console.log( jparse(false) ); // false console.log( jparse(undefined) ); // undefined
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!