Skip to content

Commit 13acc21

Browse files
committed
Tweak what should be in params
1 parent b71a65b commit 13acc21

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

Diff for: versioned_docs/version-7.x/params.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,6 @@ However, this is an anti-pattern. There are many reasons why this is a bad idea:
398398
- The same data is duplicated in multiple places. This can lead to bugs such as the profile screen showing outdated data even if the user object has changed after navigation.
399399
- Each screen that navigates to the `Profile` screen now needs to know how to fetch the user object - which increases the complexity of the code.
400400
- URLs to the screen (browser URL on the web, or deep links on native) will contain the user object. This is problematic:
401-
402401
1. Since the user object is in the URL, it's possible to pass a random user object representing a user that doesn't exist or has incorrect data in the profile.
403402
2. If the user object isn't passed or improperly formatted, this could result in crashes as the screen won't know how to handle it.
404403
3. The URL can become very long and unreadable.
@@ -409,11 +408,11 @@ A better way is to pass only the ID of the user in params:
409408
navigation.navigate('Profile', { userId: 'jane' });
410409
```
411410
412-
Now, you can use the passed `userId` to grab the user from your global store. This eliminates a host of issues such as outdated data, or problematic URLs.
411+
Now, you can use the passed `userId` to grab the user from your global cache or fetch it from the API. Using a library such as [React Query](https://tanstack.com/query/) can simplify this process since it makes it easy to fetch and cache your data. This approach helps to avoid the problems mentioned above.
413412
414413
Some examples of what should be in params are:
415414
416-
1. IDs like user id, item id etc., e.g. `navigation.navigate('Profile', { userId: 'Jane' })`
415+
1. IDs such as user id, item id etc., e.g. `navigation.navigate('Profile', { userId: 'Jane' })`
417416
2. Params for sorting, filtering data etc. when you have a list of items, e.g. `navigation.navigate('Feeds', { sortBy: 'latest' })`
418417
3. Timestamps, page numbers or cursors for pagination, e.g. `navigation.navigate('Chat', { beforeTime: 1603897152675 })`
419418
4. Data to fill inputs on a screen to compose something, e.g. `navigation.navigate('ComposeTweet', { title: 'Hello world!' })`

Diff for: versioned_docs/version-7.x/testing.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,6 @@ In the above test, we:
758758

759759
:::note
760760

761-
In a production app, we recommend using a library like [React Query](https://react-query.tanstack.com/) to handle data fetching and caching. The above example is for demonstration purposes only.
761+
In a production app, we recommend using a library like [React Query](https://tanstack.com/query/) to handle data fetching and caching. The above example is for demonstration purposes only.
762762

763763
:::

0 commit comments

Comments
 (0)