Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/idea2app/react-router-class-tools

Class Component utilities for React Router 6+, which rolls back the Class supports dropped by official team.
https://github.com/idea2app/react-router-class-tools

class component react router tool utility

Last synced: about 1 month ago
JSON representation

Class Component utilities for React Router 6+, which rolls back the Class supports dropped by official team.

Awesome Lists containing this project

README

        

# React Router class tools

**Class Component** utilities for [React Router][1] 6+

[![CI & CD](https://github.com/idea2app/React-Router-class-tools/actions/workflows/main.yml/badge.svg)][2]

[![NPM](https://nodei.co/npm/react-router-class-tools.png?downloads=true&downloadRank=true&stars=true)][3]

[![Demo](https://codesandbox.io/static/img/play-codesandbox.svg)][4]

## Feature

- [x] `withRouter()` function
- [ ] `withRouter()` decorator
- [x] `RouteComponentProps`
- [ ] `this.props.history`
- [x] `this.props.location`
- [x] `this.props.match`
- [ ] Static Context
- [x] `this.props.query`: the missing **Query object**

## Usage

```tsx
import { PureComponent } from 'react';
import { RouteComponentProps, withRouter } from 'react-router-class-tools';

export default withRouter(
class RoutePage extends PureComponent<
RouteComponentProps<{ id: string }, {}, { extra: number }>
> {
render() {
const { id } = this.props.match.params,
{ extra } = this.props.query;

return (


  • ID: {id}

  • extra: {extra}


);
}
}
);
```

## Reference

1. https://github.com/remix-run/react-router/issues/8146
2. https://segmentfault.com/a/1190000041700003

## User case

1. https://github.com/idea2app/React-MobX-Bootstrap-ts
2. https://github.com/idea2app/React-MobX-Ant-Design-ts

[1]: https://reactrouter.com/
[2]: https://github.com/idea2app/React-Router-class-tools/actions/workflows/main.yml
[3]: https://nodei.co/npm/react-router-class-tools/
[4]: https://codesandbox.io/s/react-class-router-1y99mv