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 get a link element from one list in the react component and run a link whit out clicking?

0

I have a list of messages and I am trying to get some link from that message if it exists there (and store it in studentlink const) this will happen in an event listener. getElemenBy tag and id and the name don't work, I don't know why! what is your idea? in the next step, I need to run that link whit out clicking, automatically but I didn't find any method or solution yet, how is possible?

import React from "react";
import { connect } from "react-redux";
import reactDom from "react-dom";

function MessageList(props) {
  const handleLoad = (e) => {
    if (listItems !== "") {
      let studentlink = document.getElementById("myAnchor").href;
      window.location.href = studentlink;

      alert(`${studentlink}`);
    } else {
      console.log(window.location.href);
    }
  };

  React.useEffect(() => {
    window.addEventListener("load", handleLoad);

    // cleanup this component
    return () => {
      window.removeEventListener("load", handleLoad);
    };
  }, []);

  const arr = props.studentmessage;
  const listItems = arr.map((message, index) => (
    <li key={index} id="myAnchor">
      {message}
    </li>
  ));
  return (
    <section>
      <div className="commentbox">
        <ul>{listItems}</ul>
      </div>
    </section>
  );
}

const mapStatetoprops = (state) => {
  return {
    studentmessage: state.message,
  };
};

export default connect(mapStatetoprops)(MessageList);

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