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
In several cases you might want to exclude several fields from syncing. To support this scenario, we provide a mechanism to exclude fields based on list of fields or regular expression.
64
+
### PersistNSyncOptions
65
+
66
+
In several cases, you might want to exclude several fields from syncing. To support this scenario, we provide a mechanism to exclude fields based on a list of fields or regular expressions.
> It is good to note here that each element of `include` and `exclude` array can either be a string or a regular expression.
97
100
> To use regular expression, you should either use `new RegExp()` or `/your-expression/` syntax. Double or single quoted strings are not treated as regular expression.
98
-
> You can specify whether to use either `"localStorage"`, `"sessionStorage"`, or `"cookies"` to persist the state - default `"localStorage"`.
101
+
> You can specify whether to use either `"localStorage"`, `"sessionStorage"`, or `"cookies"` to persist the state - default `"localStorage"`. Please note that `"sessionStorage"` is not persisted. Hence can be used for sync only scenarios.
102
+
103
+
### Updating options at runtime
104
+
105
+
Since version 1.2, you can also update the options at runTime by setting `__persistNSyncOptions` in your Zustand state.
Starting from version 1.2, you can also clear the persisted data by calling `clearStorage` function. It takes `name` of your store (`name` passed in `options` while creating the store), and optional `storageType` parameters.
139
+
140
+
```ts
141
+
import { clearStorage } from"persist-and-sync";
142
+
143
+
...
144
+
clearStorage("my-store", "cookies");
145
+
...
146
+
```
99
147
100
148
## Legacy / Deprecated
101
149
102
-
#### Ignore / filter out fields based on regExp
150
+
#### Ignore/filter out fields based on regExp
103
151
104
-
In several cases you might want to exclude several fields from syncing. To support this scenario, we provide a mechanism to exclude fields based on regExp. Just pass `regExpToIgnore` (optional - default -> undefined) in options object.
152
+
In several cases, you might want to exclude several fields from syncing. To support this scenario, we provide a mechanism to exclude fields based on regExp. Just pass `regExpToIgnore` (optional - default -> undefined) in the options object.
105
153
106
154
```ts
107
155
// to ignore fields containing a slug
@@ -122,7 +170,7 @@ For more details about regExp check out - [JS RegExp](https://www.w3schools.com/
122
170
123
171
### Exact match
124
172
125
-
For exactly matching a parameter/field use `/^your-field-name$/`. `^` forces match from the first caracter and similarly, `$` forces match until the last character.
173
+
For exactly matching a parameter/field use `/^your-field-name$/`. `^` forces match from the first character and similarly, `$` forces match until the last character.
0 commit comments