-
-
Notifications
You must be signed in to change notification settings - Fork 102
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
Hooks! #446
Comments
Currently methods live inside |
<Villain>{ Indside here any component can use our custom hooks }</Villain> This is how we can expose the methods as hooks: export function useCurrentPage() {
// We can access directly to our context:
return useContext(Context).currentPage;
} Example usage: const currentPage = useCurrentPage();
const navigateForward = useNavigateForward();
...
<Villain>
<div> Current page: {currentPage}</div>
<button onClick={navigateForward}> Next page </button>
</Villain> https://github.com/ReactTraining/react-router/blob/master/packages/react-router/modules/hooks.js |
I'll start to do some work on this branch, please let me know if you want to help ✌️ |
First draft of Navigation hook: const navigation = useNavigation();
// ...
{
// Total count of pages
totalPages: 24,
// Can navigate to previous page
canBack: false,
// Can navigate to next page
canForward: true,
// Current page index ( 0 = first index )
currentPage: 0,
// Current page number ( 1 = first page / cover )
currentPageNumber: 1,
// Actions:
// Go to page from index
go(index),
// Go to previous page
back(),
// Go to next page
forward(),
} |
First draft of Pages hook: const currentPages = usePages()
// Returns an array of the current image / images to render
[
{ index: 3, url: 'blob:image_url_soruce', name: 'page_0004.jpeg' }
]
// Note: if `layout` mode is set to `LAYOUT_MODE.BOOK` it will also return the next page
[
{ index: 3, url: 'blob:image_url_soruce', name: 'page_0004.jpeg' },
{ index: 4, url: 'blob:image_url_soruce', name: 'page_0005.jpeg' }
]
// Basic render example:
<div>
{ pages.map((page, key) => {
return (<img src={page.url} height={500} key={key} />)
})}
</div> |
New react hook implemented: |
Hooks are now part of the new |
Hooks will make the
api
more transparent and easy to access, there will be no need to provide a UI and devs will have free access to build controls and extensions without limitations of the current structure.Here are some initial tasks:
useNavigateToPage
,useGetZoomLevels
, etc... )The text was updated successfully, but these errors were encountered: