-
-
Notifications
You must be signed in to change notification settings - Fork 458
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2153 from Loeffeldude/master
WhenVisible useEffect function is not recreated when params change. #2152
- Loading branch information
Showing
6 changed files
with
124 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,53 @@ | ||
import { WhenVisible } from '@inertiajs/react' | ||
import { useState } from 'react' | ||
|
||
const Foo = ({ label }) => { | ||
return <div>{label}</div> | ||
} | ||
|
||
export default () => ( | ||
<> | ||
<div style={{ marginTop: '5000px' }}> | ||
<WhenVisible data="foo" fallback={<div>Loading first one...</div>}> | ||
<Foo label="First one is visible!" /> | ||
</WhenVisible> | ||
</div> | ||
export default () => { | ||
const [count, setCount] = useState(0) | ||
|
||
<div style={{ marginTop: '5000px' }}> | ||
<WhenVisible buffer={1000} data="foo" fallback={<div>Loading second one...</div>}> | ||
<Foo label="Second one is visible!" /> | ||
</WhenVisible> | ||
</div> | ||
return ( | ||
<> | ||
<div style={{ marginTop: '5000px' }}> | ||
<WhenVisible data="foo" fallback={<div>Loading first one...</div>}> | ||
<Foo label="First one is visible!" /> | ||
</WhenVisible> | ||
</div> | ||
|
||
<div style={{ marginTop: '5000px' }}> | ||
<WhenVisible data="foo" fallback={<div>Loading third one...</div>} always> | ||
<Foo label="Third one is visible!" /> | ||
</WhenVisible> | ||
</div> | ||
<div style={{ marginTop: '5000px' }}> | ||
<WhenVisible buffer={1000} data="foo" fallback={<div>Loading second one...</div>}> | ||
<Foo label="Second one is visible!" /> | ||
</WhenVisible> | ||
</div> | ||
|
||
<div style={{ marginTop: '5000px' }}> | ||
<WhenVisible data="foo" fallback={<div>Loading fourth one...</div>}></WhenVisible> | ||
</div> | ||
</> | ||
) | ||
<div style={{ marginTop: '5000px' }}> | ||
<WhenVisible data="foo" fallback={<div>Loading third one...</div>} always> | ||
<Foo label="Third one is visible!" /> | ||
</WhenVisible> | ||
</div> | ||
|
||
<div style={{ marginTop: '5000px' }}> | ||
<WhenVisible data="foo" fallback={<div>Loading fourth one...</div>}></WhenVisible> | ||
</div> | ||
|
||
<div style={{ marginTop: '6000px' }}> | ||
<WhenVisible | ||
fallback={<div>Loading fifth one...</div>} | ||
always | ||
params={{ | ||
data: { | ||
count, | ||
}, | ||
onSuccess: () => { | ||
setCount((c) => c + 1) | ||
}, | ||
}} | ||
> | ||
<Foo label={`Count is now ${count}`} /> | ||
</WhenVisible> | ||
</div> | ||
</> | ||
) | ||
} |
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