N
N
Nikita Shchypylov2019-01-18 13:29:30
React
Nikita Shchypylov, 2019-01-18 13:29:30

How to use the new React Context in stateless components?

Hello.
How can I get the Context'a value in a stateless component?
In the version with the class it works, but not with the function declaration.

export function Test(props, context) {
    console.log(` --- `, context); //не работает
    return (
        <div>Hello</div>
    )
}

Test.contextType = OnwContext // статическая переменная как в классом варианте тоже не работает

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita Shchypylov, 2019-01-18
@Nikulio

Good article on this topic.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question