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

190
Visualizações
How to update React Components from react context

How to increment a count in react context by that I need to change the count value based on some events that happens On ContextCount.js file

let count = 0;

 const createSale = async (url, formInputPrice, isReselling, id) => {
    // connect to smart contract

    const web3Modal = new Web3Modal();
    const connection = await web3Modal.connect();
    const provider = new ethers.providers.Web3Provider(connection);
    const signer = provider.getSigner();
    // value of wei of zeo of to convert to it that what metamask read
    const price = ethers.utils.parseUnits(formInputPrice, 'ether');
    // calling func() from contract takes time so use await
    const contract = fetchContract(signer);
    count += 1;
    const listingPrice = await contract.getListingPrice();
    const transaction = !isReselling
      ? await contract.createToken(url, price, { value: listingPrice.toString() })
      // else it belong to this
      : await contract.resellToken(id, price, { value: listingPrice.toString() });
    await transaction.wait();
  };
 <NFTContext.Provider value={{ count }}>
      {children}
    </NFTContext.Provider>

On React Components folder i need to pass the updated value of count when evener a createsale function is happen

So i use on components folder i created a countupdate.jsx On there import React from 'react'; i imported the context file then i use

 const { count } = useContext(ContextCount);
const updateIt = () => (
  <div>{count}</div>
);

export default updateIt;

So I need to show the updated value from ContextCount.js to Components file updateIt.jsx Does anyone know how to implement this?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It is not updated because you are using the hook wrong. Here is where you can learn all you need about hooks. The context hook should be used inside your component, like this:

const updateIt = () => {
  const { count } = useContext(ContextCount);
  return (
    <div>{count}</div>
  );
};

And here is the answer on how to update data in context from its consumer

about 4 years ago · Juan Pablo Isaza Relatório
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