0

code -

const Exne: React.FC <IProps> = ({x}) => 
    {
    console.log('input', x);    
    const [getx, assignx] = useState(x);
    console.log(getx, assignx);
    return(getx)
    };

In this code, how to access or call Exne from other files?

Thanks

vishak raj
  • 21
  • 4
  • Does this answer your question? [Exporting functions with reactjs and babel](https://stackoverflow.com/questions/44309306/exporting-functions-with-reactjs-and-babel) – thedude Jul 21 '21 at 13:20

1 Answers1

0

You can export the const and import it in another file you want to use.

in file.ts:

export const Exne: React.FC <IProps> = ({x}) => {
    console.log('input', x);    
    const [getx, assignx] = useState(x);
    console.log(getx, assignx);
    return(getx)
};

in another.ts:

import { Exne } from './file';

// and you can use Exne as you are in file.ts
Danny Zhao
  • 314
  • 1
  • 3
  • 12