Skip to content

Commit

Permalink
ComponentWillUnmount should not be deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
awpcollins authored Jan 30, 2019
1 parent b0d6e63 commit 5180327
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Props (short for properties) are a Component's configuration. They are received
- `shouldComponentUpdate` - if you’re worried about wasted renders `shouldComponentUpdate` is a great place to improve performance as it allows you to prevent a rerender if component receives new `prop`. `shouldComponentUpdate` should always return a boolean and based on what this is will determine if the component is rerendered or not.
- `componentWillUpdate` (deprecated) - rarely used. It can be used instead of `componentWillReceiveProps` on a component that also has `shouldComponentUpdate` (but no access to previous props).
- `componentDidUpdate` - also commonly used to update the DOM in response to prop or state changes.
- `componentWillUnmount` (deprecated) - here you can cancel any outgoing network requests, or remove all event listeners associated with the component.
- `componentWillUnmount` - here you can cancel any outgoing network requests, or remove all event listeners associated with the component.

#### Where in a React component should you make an AJAX request?
`componentDidMount` is where an AJAX request should be made in a React component. This method will be executed when the component “mounts” (is added to the DOM) for the first time. This method is only executed once during the component’s life. Importantly, you can’t guarantee the AJAX request will have resolved before the component mounts. If it doesn't, that would mean that you’d be trying to setState on an unmounted component, which would not work. Making your AJAX request in `componentDidMount` will guarantee that there’s a component to update.
Expand Down

0 comments on commit 5180327

Please sign in to comment.