Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add preload() method to lazy #43

Merged
merged 3 commits into from
Oct 17, 2024
Merged

feat: Add preload() method to lazy #43

merged 3 commits into from
Oct 17, 2024

Conversation

rschristian
Copy link
Member

@rschristian rschristian commented Oct 16, 2024

Still need to figure out the right song & dance for sinon to play nice, but would allow for easier preloading.

import { render } from 'preact';
import { LocationProvider, Router, Route, lazy } from 'preact-iso';

const NotFound = lazy(() => import('./pages/_404.jsx'));

function Home() {
    return (
        <a href="/404" onMouseOver={() => NotFound.preload()}>
            Not Found -- Hover me to preload `NotFound`!
        </a>
    );
}

function App() {
    return (
        <LocationProvider>
            <Router>
                <Route path="/" component={Home} />
                <Route default component={NotFound} />
            </Router>
        </LocationProvider>
    )
}

render(<App />, document.getElementById('app'));

@rschristian rschristian marked this pull request as ready for review October 17, 2024 01:53
@rschristian rschristian merged commit 4c9ed82 into main Oct 17, 2024
1 check passed
@rschristian rschristian deleted the feat/preload-lazy branch October 17, 2024 07:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants