Skip to content

Commit

Permalink
Fix useNavigation back and forward functions
Browse files Browse the repository at this point in the history
  • Loading branch information
santino committed Aug 15, 2022
1 parent 7110be8 commit 1badc3d
Show file tree
Hide file tree
Showing 7 changed files with 1,469 additions and 1,516 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

strategy:
matrix:
node-version: [16.x, 17.x]
node-version: [16.x, 18.x]

steps:
- name: Checkout repository
Expand Down Expand Up @@ -40,7 +40,7 @@ jobs:

strategy:
matrix:
node-version: [16.x, 17.x]
node-version: [16.x, 18.x]

steps:
- name: Checkout repository
Expand Down Expand Up @@ -86,7 +86,7 @@ jobs:

strategy:
matrix:
node-version: [16.x, 17.x]
node-version: [16.x, 18.x]

steps:
- name: Checkout repository
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Use Node 17.x
- name: Use Node 18.x
uses: actions/setup-node@v2
with:
node-version: 17.x
node-version: 18.x
registry-url: https://registry.npmjs.org/
- name: Install fresh dependencies
run: yarn install --ignore-engines --frozen-lockfile
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,6 @@ You can use this hook to perform programmatic navigation. It returns an object w
- `go`: navigates backward/forward by "n" entries in the stack, identified by relative position to the current page (always 0). The argument is a number, negative values will navigate backward, positive will navigate forward
- `goBack`, move backward by one entry through the history stack. No arguments
- `goForward`: move forward by one entry through the history stack. No arguments
- `canGo`: only provided by Memory Router; check if can navigate to given "n" pointer in the history stack. The argument is the same as `go`

### useHistory
```js
Expand Down
44 changes: 22 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-concurrent-router",
"version": "1.2.0",
"version": "1.2.1",
"description": "Performant routing embracing React concurrent UI patterns",
"author": "Santino Puleio",
"license": "MIT",
Expand Down Expand Up @@ -95,43 +95,43 @@
},
"devDependencies": {
"@ampproject/rollup-plugin-closure-compiler": "^0.27.0",
"@babel/core": "^7.18.2",
"@babel/eslint-parser": "^7.18.2",
"@babel/plugin-proposal-object-rest-spread": "^7.18.0",
"@babel/plugin-transform-object-assign": "^7.16.7",
"@babel/plugin-transform-react-constant-elements": "^7.17.12",
"@babel/plugin-transform-runtime": "^7.18.2",
"@babel/preset-env": "^7.18.2",
"@babel/preset-react": "^7.17.12",
"@babel/runtime": "^7.18.3",
"@babel/core": "^7.18.10",
"@babel/eslint-parser": "^7.18.9",
"@babel/plugin-proposal-object-rest-spread": "^7.18.9",
"@babel/plugin-transform-object-assign": "^7.18.6",
"@babel/plugin-transform-react-constant-elements": "^7.18.12",
"@babel/plugin-transform-runtime": "^7.18.10",
"@babel/preset-env": "^7.18.10",
"@babel/preset-react": "^7.18.6",
"@babel/runtime": "^7.18.9",
"@rollup/plugin-babel": "^5.3.1",
"@rollup/plugin-commonjs": "^22.0.0",
"@rollup/plugin-commonjs": "^22.0.2",
"@rollup/plugin-node-resolve": "^13.3.0",
"@testing-library/dom": "^8.13.0",
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/dom": "^8.17.1",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.3.0",
"@types/react": "^18.0.12",
"babel-jest": "^28.1.1",
"@types/react": "^18.0.17",
"babel-jest": "^28.1.3",
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
"bundlewatch": "^0.3.3",
"cherry-pick": "^0.5.0",
"coveralls": "^3.1.1",
"cross-env": "^7.0.3",
"doctoc": "^2.2.0",
"dtslint": "^4.2.1",
"jest": "^28.1.1",
"jest-environment-jsdom": "^28.1.1",
"lint-staged": "^13.0.0",
"jest": "^28.1.3",
"jest-environment-jsdom": "^28.1.3",
"lint-staged": "^13.0.3",
"open-cli": "^7.0.1",
"prettier-standard": "^16.4.1",
"prop-types": "^15.8.1",
"react": "^18.1.0",
"react-dom": "^18.1.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"rimraf": "^3.0.2",
"rollup": "^2.75.5",
"rollup": "^2.78.0",
"rollup-plugin-terser": "^7.0.2",
"standard": "^17.0.0",
"typescript": "^4.7.3"
"typescript": "^4.7.4"
},
"peerDependencies": {
"@babel/runtime": "^7.11.0",
Expand Down
10 changes: 4 additions & 6 deletions src/__tests__/useNavigation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ useContext.mockImplementation(() => ({
push: 'mockPush',
replace: 'mockReplace',
go: 'mockGo',
goBack: 'mockGoBack',
goForward: 'mockGoForward',
canGo: 'mockCanGo',
back: 'mockBack',
forward: 'mockForward',
foo: 'bar'
},
baz: 'qux'
Expand All @@ -27,9 +26,8 @@ describe('useNavigation', () => {
push: 'mockPush',
replace: 'mockReplace',
go: 'mockGo',
goBack: 'mockGoBack',
goForward: 'mockGoForward',
canGo: 'mockCanGo'
goBack: 'mockBack',
goForward: 'mockForward'
})
})
})
7 changes: 3 additions & 4 deletions src/useNavigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ import RouterContext from './RouterContext'

const useNavigation = () => {
const {
history: { push, replace, go, goBack, goForward, canGo }
history: { push, replace, go, back, forward }
} = useContext(RouterContext)

return {
push, // pushes a new entry onto the history stack
replace, // replaces the current entry on the history stack
go, // navigates backward/forward by `n` entries in the stack, identified by relative position to the current page (always 0)
goBack, // move backward by one entry through history stack
goForward, // move forward by one entry through history stack
canGo // only provided by MemoryHistory; check if can navigate to given `n` pointer in history stack
goBack: back, // move backward by one entry through history stack
goForward: forward // move forward by one entry through history stack
}
}

Expand Down
Loading

0 comments on commit 1badc3d

Please sign in to comment.