Necesito entender la propuesta de usar window.location?.search?.split('=')[1] y por qué id toma el valor de window.location?.search?.split('=')[1]
Código:
function EndScreen() { const [score, setScore] = React.useContext(ScoreContext); /* console.log('history', window.location?.search?.split('=')[1]); */ return ( <div className="EndScreen"> <h1>Test finished</h1> <br></br> <h3> You scored:</h3> <h1 style={{ fontSize: '70px' }}> {score} / {Questions?.length} </h1> <br></br> <br></br> <button onClick={() => FormService.update({ id: window.location?.search?.split('=')[1], data: { score: score } }) .then(() => { alert('Score updated'); }) .catch(() => { alert('Score did NOT update') }) } > Apply for job </button> </div> ); }Es para trabajar con cadena de querystring :
si su URL es, google.com/user/userData?id=123,email=exp@gmail.com
llamamos usuario y path de datos de usuario e identificación y correo electrónico se llaman querystrings de consulta
location.search; // Returns:'?id=123,email=exp@gmail.com' let newArray = location.search.split('=') // Returns:['?id','123',',email','exp@gmail.com']