Skip to content

Commit 90ed895

Browse files
committed
Format subscription example
1 parent 2ec5611 commit 90ed895

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

‎src/content/reference/rules/components-and-hooks-must-be-pure.md‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,16 +187,16 @@ This is fine because the mutation is local and doesn't affect other components.
187187

188188
Problematic 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
207207
Correct 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
},[]);

0 commit comments

Comments
 (0)