D
D
Demigodd2019-03-03 17:09:08
JavaScript
Demigodd, 2019-03-03 17:09:08

How to properly work with state in Redux?

Imagine there is a tickets component.
Their state is stored in Redux. (Array with objects)
With this piece of code, I draw each ticket in applications.

// Main Component
  this.props.tickets.map((ticket) => {
    return <TicketRow key={ ticket.id } ticket={ ticket } />
  })

In this component, I have a button that opens a Dialog Window when clicked.
// TicketRow Component
  <Button onClick={this.props.openDialog}>Open Modal</Button>

  <DialogWindow />

Dialog also has state stored in Redux, just Boolean ( Open ). The question is how to send a ticket object from TicketRow ComponentDialog Window Component
when clicking on the Open Modal button ? For example, there are 10 tickets, when you click on the 3rd one, a Modal will open in which this ticket number 3 will be written.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Filippov, 2019-03-03
@Demigodd

openDialog must be an action that you dispatch via connect

M
Max, 2019-03-03
@mbelskiy

If DialogWindow is part of TicketRow, then when clicking on the button, change TicketRow state.isDialogOpen=true, check the
A flag in the renderer and propagate the ticket object to the DialogWindow.
As a result, Redux is not needed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question