Why are the props onClose and onOpen marked as required in the SwipeableDrawer in Material-UI?

Viewed 652

What I understand about the need of properties like onOpen and onClose is that they try to implement the Observer pattern.

So, why should a client of the SwipeableDrawer that doesn't want to observe those events provide values for those properties? In my case, for example, since I do not want to be an observer, I had to provide empty arrow functions as values.

What is the rationale for this? What am I missing?

1 Answers

This is not an implementation of the Observer pattern. In the API docs for onOpen it says the following:

Callback fired when the component requests to be opened.

The key here is that it "requests" to be opened (but its open/close state has not changed), and you decide whether or not to change the state that you are passing in to the open prop. The same is true for the onClose prop. This allows you to inspect the details of the event in conjunction with other state within your app to decide whether or not the open state of the drawer changes.

Related