Skip to content

Commit

Permalink
docs(react-context-selector): removed the mention of non-existent `us…
Browse files Browse the repository at this point in the history
…eContextSelectors` and fixed the example (#33146)
  • Loading branch information
Jokero authored Oct 29, 2024
1 parent 22d14ef commit e1644c3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "docs: removed the mention of non-existent useContextSelectors and fixed the example",
"packageName": "@fluentui/react-context-selector",
"email": "[email protected]",
"dependentChangeType": "patch"
}
10 changes: 5 additions & 5 deletions packages/react-components/react-context-selector/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# `@fluentui/react-context-selector`

React `useContextSelector()` and `useContextSelectors()` hooks in userland.
React `useContextSelector()` hook in userland.

## Introduction

Expand Down Expand Up @@ -40,12 +40,12 @@ interface CounterContextValue {

// 💡 The same syntax as native React context API
// https://reactjs.org/docs/context.html#reactcreatecontext
const CounterContext = createContext<CounterContextValue>({});
const CounterContext = createContext<CounterContextValue>({} as CounterContextValue);

const CounterProvider = CounterContext.Provider;

// not necessary but can be a good layer to mock for unit testing
const useCounterContext = <T>(selector: ContextSelector<CounterContextValue, T>) =>
const useCounterContext = <T,>(selector: ContextSelector<CounterContextValue, T>) =>
useContextSelector(CounterContext, selector);

const Counter1 = () => {
Expand All @@ -58,10 +58,10 @@ const Counter1 = () => {
};

const Counter2 = () => {
const count1 = useCounterContext(context => context.count2);
const count2 = useCounterContext(context => context.count2);
const increment = useCounterContext(context => context.incrementCount2);

return <button onClick={increment}>Counter 1: {count1}</button>;
return <button onClick={increment}>Counter 2: {count2}</button>;
};

export default function App() {
Expand Down

0 comments on commit e1644c3

Please sign in to comment.