Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

157
Visualizações
Cannot show on screen <Input> value

I'm trying to complete my project and now I need to show two counter respectively one for the start day and one for the end day of a prenotation. That's my current situation:

import  PrenotationContext  from '../context/PrenotationContext.jsx';
const Transactions = () => {
    const {currentAccount, places} = useContext(PrenotationContext);
    return (...
       <div>
        {places.reverse().map((place,i) => (
           <PlaceCard key={i} {...place} />
         ))}
        </div>
            ...
}

const PlaceCard = ({id, placeAddress,description,price, owner, isActive}) => {
  //implementation of prenotation
  const {isLoading,handleDate, rentPlace, setInactive} = useContext(PrenotationContext);

  const Input = ({placeholder, name, type, value, handleDate}) => (
    <input 
        placeholder={placeholder}
        type={type}
        step="1"
        value = {value}
        onChange={(e) => handleDate(e, name)}
    />
  );
  ...
return(
   <div>
    ...
    <Input placeholder="Start Day" name="startDay" type="number" handleDate={handleDate}/>
    <Input placeholder="End Day" name="endDay" type="number" handleDate={handleDate}/>
     ...
   </div>
);
export default Transactions

And here is PrenotationContext.json:

  export const PrenotationProvider = ({children}) => {
    ...
    const [date, setDate] = useState({startDay: 0, endDay:0});
    ...
    const handleDate = (e,name) => {
        console.log(e.target.value);
        console.log(name)
        setDate((prevState) => ({...prevState, [name]: e.target.value}))
    }
    ...
    return (
            <PrenotationContext.Provider 
               value={{...,
                       handleDate,
                       ...
                       isLoading,
                       setInactive,
            }}>
                {children}
            </PrenotationContext.Provider>
    );
};

The two logs in "handleDate" are the following:

  • (1, startDay) the first time
  • (-1, startDay) and so on for all the other times

and no value on screen

Instead trying to log the prevState inside handleDate (causing exception) will cause the logs and also on the webpage the correct output value (1,2,3...)

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda