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

v3: history state hook #349

Merged
merged 12 commits into from
Oct 6, 2023
Merged

v3: history state hook #349

merged 12 commits into from
Oct 6, 2023

Conversation

jeetiss
Copy link
Collaborator

@jeetiss jeetiss commented Oct 1, 2023

Api for useHistoryState, should solve all problems with history.state


usage example:

const Component = () => {
  const state = useHistoryState();

  // some logic with state
  // console.log(state) 
  // ^ { hello: 'world' }
}

// somewhere in the app
navigate('/path', { state: { hello: 'world' }})

TODOs:

  • types
  • link component
  • preact
  • check exports

closes #102
related #346

@jeetiss jeetiss requested a review from molefrog October 1, 2023 13:27
@github-actions
Copy link

github-actions bot commented Oct 1, 2023

size-limit report 📦

Path Size
packages/wouter/esm/index.js 1.44 KB (+0.41% 🔺)
packages/wouter/esm/use-browser-location.js 694 B (0%)
packages/wouter-preact/esm/index.js 977 B (+0.42% 🔺)
packages/wouter-preact/esm/use-browser-location.js 255 B (0%)

@jeetiss jeetiss marked this pull request as ready for review October 4, 2023 11:16
@jeetiss jeetiss self-assigned this Oct 4, 2023
to: string | URL,
options?: { replace?: boolean }
) => void;
export const useHistoryState: <T = any>() => T;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can rename this file to use-browser-location, as well as move everything that goes before export type Primitive to index.d.ts

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed the file.

but moving is not great because it is harder to maintain preact types

Copy link
Owner

@molefrog molefrog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add a one-liner spec to test that Link can accept state prop?

@jeetiss jeetiss merged commit 09719e7 into v3 Oct 6, 2023
3 checks passed
@jeetiss jeetiss deleted the use-history-state branch October 6, 2023 06:52
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