Answer the question
In order to leave comments, you need to log in
How to organize a multi-panel application in react + redux?
Hello
, I'm trying to write a mobile app using React+Redux. To simplify, it looks like this
<Slides>
<Slide>
<OrderForm>
<Button>настроить параметр 1</Button>
<Button>настроить параметр 2</Button>
</OrderForm>
</Slide>
</Slides>
<Slides>
<Slide>
<OrderForm>
<Button>настроить параметр 1</Button>
<Button>настроить параметр 2</Button>
</OrderForm>
</Slide>
<Slide>
<OrderDetail1>
<input/>
</OrderDetail1>
</Slide>
<Slide>
<OrderDetail2>
<input/>
</OrderDetail2>
</Slide>
</Slides>
export const addSlide = (content) => {
return {
type: 'ADD_SLIDE',
payload: content
}
}
<Button onClick={() => {
this.props.addSlide(<OrderDetail1 {...somedata}/>)
}}>настроить параметр 1</Button>
let slides = this.props.slides.map((slide, index) => {
let content;
switch (slide.type) {
case 'order_detail1':
content = <OrderDetail1/>
break;
....
}
return <Slide>{content}</Slide>
})
...
<Slides>{slides}</Slides>
Answer the question
In order to leave comments, you need to log in
That's right, you have a fundamentally wrong approach. React-router is specifically used for this.
In general, the mistake was in understanding the work of React + Redux, and in particular that
there is no moment of rendering this Orderdetail, and it must be redrawn in its component. this can be done by attaching your own reducer to it, which will react to changes and cause a redraw.
This is not a solution, the question itself is not correct. Everything works there if you correctly configure the reducer of those components that are called in addSlide
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question