reading-notes


Project maintained by mr-atta Hosted on GitHub Pages — Theme by mattgraham

Context API - Behaviors



Review, Research, and Discussion

When you have multiple contexts, what component type should you use (class/function) and why ❓ πŸ“

function
more effecience and less complexity, to deal with multiple contexts

What are some good use cases for using the Context API for global state ❓ πŸ“

How can you best test context ❓ πŸ“

The best way to test Context is to make our tests unaware of its existence and avoiding mocks. We want to test our components in the same way that developers would use them (behavioral testing) and the way they would run in our applications (integration testing).



Behavioural Testing

Behavioural Testing is a testing of the external behaviour of the program, also known as black box testing. It is usually a functional testing.

What is context behavior?♦

This term refers to the situation or circumstances in which an event occurs…the particular setting in which the event occurs. For example, when attempting to understand behavior, it is important to look at the situation or circumstances present at the time of the behavior.


Context

Context provides a way to pass data through the component tree without having to pass props down manually at every level.

When to Use Context

note : If you only want to avoid passing some props through many levels, component composition is often a simpler solution than context.

API


hooks and context example

Snackbars in React: An Exercise in Hooks and Context.

Snackbars

const { addAlert } = useSnackBars()
> ...
> addAlert('Your profile is updated!')




πŸ“Œ context api

πŸ“Œ hooks and context example

πŸ“Œ react context links