Answer the question
In order to leave comments, you need to log in
How to write a HOC component in ReactJS?
Learning React patterns, going through the topic with HOC (Higher Order Components).
There is a "Teacher" code that looks like this:
const with-BookStore-Service = () => (wraped) => {
return (props) {
return (
<Consumer>
{
(value) => {
return (
<Wraped {...props}
)
}
}
<Consumer>
)
}
with-BookStore-Service = () => (wrapped) =>
const withTest = (wraped) => (props) => {
return (
<Consumer>
{
(value) => {
return (
<Wraped {...props}>
)
}
}
<Consumer>
)
}
Answer the question
In order to leave comments, you need to log in
() => (wraped)
It will make sense if there are some parameters in the first brackets.
That is, you can make a function that will be somehow configured, which can be called by passing wraped.
For example
const withBookStoreService = (consProps) => (wraped) => {
return (props) {
return (
<Consumer ...consProps>
{
(value) => {
return (
<Wraped {...props}
)
}
}
<Consumer>
)
}
const hoc1 = withBookStoreService(props)
const hoc2 = withBookStoreService(otherProps)
const wrappedInHoc1 = hoc1(component)
const wrappedInHoc2 = hoc2(component)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question