0

this is my first time to develop a react application.

I am encountering difficulties when trying to retrieve the value of const from another component to another. If I import and export the component, I cannot access the value of the const.

Am I doing it incorrect? Are there any better approaches to dynamically update the axios get request that is triggered in button click from another component

Component 1 index.js

import Panel from "../TransactionPanel";

const getServerData = async ({ filters, sortBy, pageSize, pageIndex }) => {
  await new Promise(resolve => setTimeout(resolve, 500));


  //set the detail dynamically using the retrieved value from another component (checkedMap)
  //can be also send the whole link
  let detail = 111;

  // Get our base data
  const res = await axios.get(
    "http://link_here/" +
      detail +
      "/details"
  );
  let rows = res.data;

This is where I get the value in another component using useState hook

Component 2 index.js

export default function({ infinite }) {
const [checkedMap, setCheckedMap] = useState(new Map());

Thank you very much for your help.

skyboyer
  • 22,209
  • 7
  • 57
  • 64
Dan
  • 559
  • 4
  • 9
  • 23
  • Please share more details on what exactly you are trying to achieve. The current post is very vague as it does't state how you are calling the method and and what variables you are trying to use. – Shubham Khatri May 24 '19 at 08:31
  • I recommend you to use redux to share value and updated state between components. In case you don't want to use redux yet, check out this answer https://stackoverflow.com/questions/21285923/reactjs-two-components-communicating – DarknessZX May 24 '19 at 09:32

0 Answers0