Answer the question
In order to leave comments, you need to log in
Which of these is a real container in react?
I meet a lot of formulations of different types of components and began to get a little confused.
Is a component that renders another component and passes data to it a container?
For example
const Nav = ({data}) => <a>{data}</a>;
class NavContainer extends Component = {
render () {
return(
<Nav data="Hi" />
)
}
};
const Nav = ({data}) => <a>{data}</a>;
const navContainer = (Component) => {
return ({text, ...props}) => {
return(
<Component data={text} {...props} />
)
}
};
const withTextNav = navContainer(Nav);
<withTextNav text="hi" />
Answer the question
In order to leave comments, you need to log in
I meet a lot of formulations of different types of components and began to get a little confused.
And you will meet more. Everyone comes up with their own, "slightly more correct" definition.
For some, a container is one thing, and for some it’s completely different, and the third will say that there are no real containers there at all, because real ones were only in the 80s and then they began to do some shit.
the main thing is to understand that the specific person who tells you this understands this word. Call it what you want - if you work in a team - then agree on what the term means. If it's on its own, then it doesn't matter.
The only thing worth focusing on is the terminology adopted in the official documentation. It also explains in detail what it all means. There are no containers as a separate term, the word is used utilitarianly.
I call containers such components that do not contain jsx markup, they work with data and pass it to other components (stupid), which in turn do nothing with data, but substitute them in jsx and return markup
Компонент-контейнер содержит логику, которая одинаковая/практически одинаковая для нескольких компонентов. В итоге, чтобы не дублировать один и тот же код в разных компонентах и не менять его то тут, то там при каких-либо изменениях их держат в одном контейнере.
Выглядит это примерно так:
const Container = (View) => {
return class extends Component {
state = { num: 1 };
render() {
return <View {..this.state} {...this.props} />
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question