-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(react): conditionally self-accept fast-refresh HMR (#10239)
Co-authored-by: Alec Larson <[email protected]>
- Loading branch information
1 parent
cba13e8
commit e976b06
Showing
7 changed files
with
160 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { useContext } from 'react' | ||
import { CountContext } from './CountProvider' | ||
|
||
export function ContextButton() { | ||
const { count, setCount } = useContext(CountContext) | ||
return ( | ||
<button id="context-button" onClick={() => setCount((count) => count + 1)}> | ||
context-based count is: {count} | ||
</button> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { createContext, useState } from 'react' | ||
export const CountContext = createContext() | ||
|
||
export const CountProvider = ({ children }) => { | ||
const [count, setCount] = useState(0) | ||
return ( | ||
<CountContext.Provider value={{ count, setCount }}> | ||
{children} | ||
<div id="context-provider">context provider</div> | ||
</CountContext.Provider> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// This un-exported react component should not cause this file to be treated | ||
// as an HMR boundary | ||
const Unused = () => <span>An unused react component</span> | ||
|
||
export const Foo = { | ||
is: 'An Object' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Foo } from './no-exported-comp' | ||
|
||
export default function Parent() { | ||
console.log('Parent rendered') | ||
|
||
return <div id="parent">{Foo.is}</div> | ||
} |