File tree Expand file tree Collapse file tree
src/content/reference/rules Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -187,16 +187,16 @@ This is fine because the mutation is local and doesn't affect other components.
187187
188188Problematic case:
189189``` js
190- function SubscriptionExample (){
190+ function SubscriptionExample () {
191191 let subscriptionRef = useRef (null );
192192 // 🔴 Don't do this during render
193- if (subscriptionRef .current == null ){
193+ if (subscriptionRef .current === null ) {
194194 subscriptionRef .current = store .subscribe (() => {
195195 console .log (" Store Changed" )
196196 });
197197 }
198- useEffect (() => {
199- return () => {
198+ useEffect (() => {
199+ return () => {
200200 subscriptionRef .current ? .unsubscribe ();
201201 }
202202 },[]);
@@ -206,13 +206,13 @@ This is a problematic use of lazy initialization because it perfroms an external
206206
207207Correct approach:
208208` ` ` js
209- function SubscriptonExample (){
209+ function SubscriptonExample () {
210210 const subscriptionRef = useRef (null );
211- useEffect (() => {
212- subscriptionRef .current = store .subscribe (() => {
211+ useEffect (() => {
212+ subscriptionRef .current = store .subscribe (() => {
213213 // ..
214214 })
215- return () => {
215+ return () => {
216216 subscriptionRef .current ? .unsubscribe ();
217217 }
218218},[]);
You can’t perform that action at this time.
0 commit comments