Я назначаю переменную props переменной компонента, и когда я изменяю переменную компонента, я меняю props ...
Родительский компонент:
const prova = [
{
1: 'a'
},
{
2: 'b'
},
{
3: 'c'
},
{
4: 'd'
},
{
5: 'e'
}
]
class SearchScreen extends React.Component {
...
<ScrollHorizontalTwoColumns categories={prova} title="Your Categories" seeAll={true}/>
...
Дочерний компонент:
class ScrollHorizontalTwoColumns extends React.Component {
categories1 = "";
categories2 = "";
constructor(props) {
super(props);
console.warn(this.props.categories);
if (typeof this.props.categories === 'object' && this.props.categories.length > 0){
this.categories1 = this.props.categories;
this.categories2 = this.categories1.splice(0, Math.ceil(this.categories1.length / 2))
}
console.warn(this.props.categories);
}
Второе предупреждение отличается от первого предупреждения ...
![android](https://i.ibb.co/FVNvD2M/Captura-de-pantalla-2019-09-19-a-les-16-54-25.png)
РЕДАКТИРОВАНИЕ РЕШЕНО:
Он должен изменить this.categories1 = this.props.categories;
на this.categories1 = [...this.props.categories];