How to call getter of function in other file

  javascript, typescript

I have this function in my index.js :

import React, { useState, useEffect } from 'react';

export const getters = {
  aPrice:null,
  bPrice:null
}

const setters = {
  aPrice:null,
  bPrice:null
}

export const Toto = () => {
  [getters.aPrice , setters.aPrice] = useState(null);
  [getters.bPrice , setters.bPrice] = useState(null);

  // runs once
  useEffect(() => {
    setters.aPrice(50));
    setters.bPrice(40);
  }, []);

  return (
    <SectionWrapper>
      ...
    </SectionWrapper>
  )
}

And I woudlike to get aPrice in this file main.js :

So I already import this : import {Toto, getters} from index.js

When I try to console it :

console.log(getters.aPrice);

I have the value null ?

Source: Ask Javascript Questions

LEAVE A COMMENT