Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
@imjakechapman/use-nested-match
Advanced tools
Currently with React Router V6 (still in alpha), using `activeClassName` on a top level `<NavLink>` on works with exact match. This hook helps mitigate the issue until they rework the internal `useMatch` to work correctly against nested routes.
Currently with React Router V6 (still in alpha), using activeClassName
on a top level <NavLink>
on works with exact match.
This hook helps mitigate the issue until they rework the internal useMatch
to work correctly against nested routes.
Example: https://codesandbox.io/s/react-router-v6-utility-function-usenestedmatch-44q73
useNestedMatch(test: string, opts: { type: string; path: string })
There are 2 type
options available
They do exactly what they sound like they do. startsWith
checks if the path starts with the test string and endsWith
checks if the path name ends with the test string. If you don't pass a type param it will match against the entire path.
provide a path to check against, default is ''
. For now I just pass pathname
you can retrieve from react-router-dom's useLocation
hook.
npm install @imjakechapman/use-nested-match
or
yarn add @imjakechapman/use-nested-match
then
We have some some nested routers and a top level NavLink
we want to stay active. import useNestedMatch
and test against whatever your heart desires.
location.pathname '/account/921808/somenestedroute/edit'
import { useLocation } from 'react-router-dom'
import { useNestedMatch } from '@imjakechapman/use-nested-match'
const App = () => {
const { pathname } = useLocation()
// returns true
const accountLinkActive = useNestedMatch('account', {
type: 'startsWith',
path: pathname
})
// returns false
const settingsLinkActive = useNestedMatch('settings') // false
// returns true
const editLinkActive = useNestedMatch('edit', {
type: 'endsWith',
path: pathname
})
return (
<NavLink className={
classnames({ 'my-active-class': accountLinkActive })
}>
Account
</NavLink>
<NavLink className={
classnames({ 'my-active-class': settingsLinkActive })
}>
Settings
</NavLink>
<NavLink className={
classnames({ 'my-active-class': editLinkActive })
}>
Edit
</NavLink>
)
}
FAQs
Currently with React Router V6 (still in alpha), using `activeClassName` on a top level `<NavLink>` on works with exact match. This hook helps mitigate the issue until they rework the internal `useMatch` to work correctly against nested routes.
The npm package @imjakechapman/use-nested-match receives a total of 0 weekly downloads. As such, @imjakechapman/use-nested-match popularity was classified as not popular.
We found that @imjakechapman/use-nested-match demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.