How to Remove Board from Redux store-React js, red

2019-08-21 08:16发布

Here i am creating new board by clicking on button, Once i enter board page i have option of creating new widgets

If user is not creating new widget and click backtoboards button , boards should not be created

here board is getting created,i am able to see the boards with out saving,

If i refresh the page board is not seen.

can i get some suggestion on how to prevent creating board if back to board button is clicked

click on back to board below function will be called

Back to board

manageShowBoard = (selectedBoard) => {
this.setState({ selectedBoard });
};

标签: reactjs redux
2条回答
SAY GOODBYE
2楼-- · 2019-08-21 08:21

The simple approach can be in your new Board component (where you are creating widgets), you can keep the widgets count. When the user clicks the back button, you can check the widgets count. If your widgets count is greater than 0, then you can add that board in the Parent component where you can maintain all boards data.

Parent:

class Parent {
  constructor(props){
    super(props);
    this.boardsList = [];
  }

  updateBoards = (newBoard) => {
    this.boardsList.push(newBoard);
    this.setState({renderAgain: true});
  }

  render(){
    return <Board updateBoards={this.updateBoards} />;
  }

}

Board:

class Board {

  onClickBackButton = () => {
    if(widgetsCount > 0){
      this.props.updateBoards(boardData);
    }
    else {
      ...normal back button functionality...
    }
  }

}
查看更多
做自己的国王
3楼-- · 2019-08-21 08:43

First of all, you have to pass the selectedStoryboard as the payload of the action, then simply:

case types.REMOVE_STORYBOARD:
{
  const boardToRemove = ... // get from action payload
  return {
     ...state,
    boardList: state.boardList.filter(board => board !== boardToRemove);
  };
}
查看更多
登录 后发表回答