0

I have an arrow function that get exported and used in another file (I'm using React, but it doesn't matter). In my function I have an object with some properties. However I can't seem to access the object.

I tried 2 approaches:

1. Export in export:

I tried exporting inside an existing export, but that didn't work:

export const TextComponent = ({ text }) => {
    export const Props = {
        text: [text]
    }
    return <p>{Props.text}</p>
}

2. Trying to access it in another file without an export

like:

export const TextComponent = ({ text }) => {
    const Props = {
        text: [text]
    }
    return <p>{Props.text}</p>
}

//file 2

TextComponent.Props ...

None of these seem to work, is there a way to access this object from a function in another file?

1 Answer 1

1

You may try to export the object and then inside your function you can perform the property assignment for that object. Something like this:

export const Props = {};
export const TextComponent = ({ text }) => {
    Props.text = [text]
    return <p>{Props.text}</p>
}
Sign up to request clarification or add additional context in comments.

1 Comment

You can do this in JS, however, it makes no sense, if you are working in a React environment you shouldn´t use Props this way

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.