You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For example, the render function is used extensively in React, and if you extend React.Component, tslint-override will trigger, and 'fix' it to have an override comment.
The text was updated successfully, but these errors were encountered:
I don't really see what is wrong with this behaviour. On the contrary, exceptional behaviours make it harder to read someone else's code.
Look for instance at this piece of code I found in the React docs:
classScrollingListextendsReact.Component{constructor(props){super(props);this.listRef=React.createRef();}getSnapshotBeforeUpdate(prevProps,prevState){// Are we adding new items to the list?// Capture the scroll position so we can adjust scroll later.if(prevProps.list.length<this.props.list.length){constlist=this.listRef.current;returnlist.scrollHeight-list.scrollTop;}returnnull;}componentDidUpdate(prevProps,prevState,snapshot){// If we have a snapshot value, we've just added new items.// Adjust scroll so these new items don't push the old ones out of view.// (snapshot here is the value returned from getSnapshotBeforeUpdate)if(snapshot!==null){constlist=this.listRef.current;list.scrollTop=list.scrollHeight-snapshot;}}render(){return(<divref={this.listRef}>{/* ...contents... */}</div>);}}
I know about render and componentDidUpdate but I have never heard of getSnapshotBeforeUpdate. Is this a built-in react method? Without override I need to break my flow and check it myself. What if this class had many custom methods as well. override helps tell apart what's component lifecycle and what is not. (Many might be tempted to insert a fat multi-line comment to cut their file in sections like // ===== Lifecycle methods ===== for that purpose actually).
Granted render is über-common and everyone knows about it, but the feature you are asking for opens the door to abuse for little apparent benefit.
I'll keep this open to debate but I am against it for now.
For example, the
render
function is used extensively in React, and if you extend React.Component, tslint-override will trigger, and 'fix' it to have an override comment.The text was updated successfully, but these errors were encountered: