Interceptors deprecated - goransh/react-super-context GitHub Wiki
The interceptors
feature has been deprecated in version 0.2.1 and will be removed in, or before, version 1.0.0. This was done because the feature was a bit more complex than it had to be and only served one simple use case. The goal of this library is to simplify contexts and this feature didn't fit that goal.
Replacement
If you were not using the memoInterceptor
like the example below, you can ignore this.
const [TodoContext, useTodoContext] = createSuperContext(
() => {
...
return { todoItems, addTodoItem, removeTodoItem };
},
{
interceptors: [memoInterceptor]
}
)
Option 1: Just remove it
The recommended option is to simply remove the memoInterceptor
. The interceptor was intended as a performance improvement, but in most cases it likely didn't provide any performance benefits or could even make it worse in some cases.
useAutoMemo
Option 2: Use this option if you rely on the context's state updating infrequently for performance reasons. For instance, if you have components higher up in the tree (above the context) that update state frequently, causing the context state to also update frequently and subsequently causing some expensive calculation to execute frequently, then you can wrap the context's returned value in a useAutoMemo
.
Install this package and replace code as follows:
createSuperContext(() => {
...
return useAutoMemo({ todoItems, addTodoItem, removeTodoItem });
})