Answer the question
In order to leave comments, you need to log in
How to export properties from a component?
Good evening. Tell me if it is possible to export a property from a React component. For example, I created a component in the home folder. In this folder, in addition to the home.jsx component itself, there is an index.js from which Home is exported. Home has a getAdress() method that returns a string with the address. Can I separately export this method to index.js? The question is specifically focused on whether it is possible to export a component method separately from the component itself!
Answer the question
In order to leave comments, you need to log in
so don't write it in a component,
// Home.jsx
export const getAddress = () => {}
export default const Home = () => {}
// index.js
import {getAddress}, Home from "./Home"
class ExpampleComponent extends React.Component {
static exampleStaticMethod() {
// some stuff without using 'this' keyword
}
}
export default ExpampleComponent;
import ExpampleComponent from './ExpampleComponent';
ExpampleComponent.exampleStaticMethod();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question