Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commita4f79d6

Browse files
authored
use next.js built-in router hooks (#759)
* fix(warning): invalid argument supplied to oneOfType, expected an array* refactor(route): use hooks instead of withRouter
1 parent428eae9 commita4f79d6

File tree

8 files changed

+19
-62
lines changed

8 files changed

+19
-62
lines changed

‎src/components/Buttons/ArrowButton.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const ArrowButton = ({
6565
}
6666

6767
ArrowButton.propTypes={
68-
children:T.oneOfType(T.string,T.node),
68+
children:T.oneOfType([T.string,T.node]),
6969
size:T.oneOf(['tiny','small','medium','large']),
7070
direction:T.oneOf(['left','right']),
7171
transparentFirst:T.bool,

‎src/components/Buttons/Button.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const Button = ({ children, ghost, type, onClick, size, className }) => {
3333
}
3434

3535
Button.propTypes={
36-
children:T.oneOfType(T.string,T.node),
36+
children:T.oneOfType([T.string,T.node]),
3737
ghost:T.bool,
3838
type:T.oneOf(['primary','red','ghost']),
3939
size:T.oneOf(['default','small']),

‎src/components/NaviMenu/index.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ NaviMenu.propTypes = {
123123
title:T.string,
124124
icon:T.string,
125125
displayType:T.string,
126-
fixedIcon:T.oneOfType(T.string,T.node),
126+
fixedIcon:T.oneOfType([T.string,T.node]),
127127
pinNumber:T.number,
128128
childMenu:T.arrayOf(
129129
T.shape({

‎src/components/Navigator/MainEntries.js‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
importReactfrom'react'
22
importTfrom'prop-types'
33
importLinkfrom'next/link'
4-
import{withRouter}from'next/router'
4+
import{useRouter}from'next/router'
55

66
import{ICON_CMD}from'@/config'
77
import{ROUTE}from'@/constant'
@@ -14,7 +14,8 @@ import { Wrapper, DotDivider, SiteLink, Icon } from './styles/main_entries'
1414

1515
constsplitMargin='7px'
1616

17-
constMainEntries=({ router, type})=>{
17+
constMainEntries=({ type})=>{
18+
constrouter=useRouter()
1819
constmainPath=getRouteMainPath(router.asPath)
1920

2021
return(
@@ -95,4 +96,4 @@ MainEntries.defaultProps = {
9596
type:null,
9697
}
9798

98-
exportdefaultReact.memo(withRouter(MainEntries))
99+
exportdefaultReact.memo(MainEntries)

‎src/components/Navigator/index.js‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
importReactfrom'react'
88
importTfrom'prop-types'
99
import{contains}from'ramda'
10-
import{withRouter}from'next/router'
10+
import{useRouter}from'next/router'
1111

1212
import{ROUTE,C11N}from'@/constant'
1313
import{buildLog,getRoutePathList}from'@/utils'
@@ -18,7 +18,8 @@ import BriefView from './BriefView'
1818
/* eslint-disable-next-line */
1919
constlog=buildLog('c:Navigator:index')
2020

21-
constNavigator=({ curCommunity, layout, router})=>{
21+
constNavigator=({ curCommunity, layout})=>{
22+
constrouter=useRouter()
2223
const[mainPath,subPath]=getRoutePathList(router.asPath)
2324

2425
if(
@@ -49,4 +50,4 @@ Navigator.defaultProps = {
4950
layout:C11N.DIGEST,
5051
}
5152

52-
exportdefaultReact.memo(withRouter(Navigator))
53+
exportdefaultReact.memo(Navigator)

‎src/components/Switcher/IconSwitcher.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ IconSwitcher.propTypes = {
7070
items:T.arrayOf(
7171
T.shape({
7272
iconSrc:T.string,
73-
localIcon:T.oneOfType(T.string,T.node),
73+
localIcon:T.oneOfType([T.string,T.node]),
7474
key:T.string,
7575
})
7676
).isRequired,

‎src/containers/Route/index.js‎

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,16 @@
55
*/
66

77
importReactfrom'react'
8-
import{inject,observer}from'mobx-react'
9-
import{withRouter}from'next/router'
8+
import{useRouter}from'next/router'
109

11-
// import Link from 'next/link'
12-
13-
import{buildLog,storePlug}from'utils'
14-
import{init,uninit}from'./logic'
15-
16-
/* eslint-disable-next-line */
17-
constlog=buildLog('C:Route')
18-
19-
classRouteContainerextendsReact.Component{
20-
componentDidMount(){
21-
const{ route, router}=this.props
22-
init(route,router)
23-
}
24-
25-
componentWillUnmount(){
26-
uninit()
27-
}
28-
29-
render(){
30-
return<React.Fragment/>
31-
}
32-
}
33-
34-
exportdefaultinject(storePlug('route'))(observer(withRouter(RouteContainer)))
35-
36-
/*
37-
import React from 'react'
38-
import { withRouter } from 'next/router'
39-
40-
// import Link from 'next/link'
41-
42-
import { connectStore, buildLog } from '@/utils'
10+
import{connectStore}from'@/utils'
4311
import{useInit}from'./logic'
4412

45-
const RouteContainer = ({ route, router }) => {
13+
constRouteContainer=({ route})=>{
14+
constrouter=useRouter()
4615
useInit(route,router)
4716

4817
return<React.Fragment/>
4918
}
5019

51-
export default connectStore(withRouter(RouteContainer))
52-
53-
*/
20+
exportdefaultconnectStore(RouteContainer)

‎src/containers/Route/logic.js‎

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,6 @@ const browserHistoryBtnClicked = popstate => {
1515
// ###############################
1616
// init & uninit
1717
// ###############################
18-
exportconstinit=(_store,routeObj)=>{
19-
if(store)returnfalse
20-
21-
store=_store
22-
// sync init router info
23-
const{ mainPath, subPath}=parseURL(routeObj)
24-
const{ query}=routeObj
25-
26-
store.mark({ mainPath, subPath, query})
27-
28-
Global.onpopstate=browserHistoryBtnClicked
29-
}
30-
31-
exportconstuninit=()=>{}
3218

3319
exportconstuseInit=(_store,routeObj)=>{
3420
useEffect(()=>{
@@ -42,3 +28,5 @@ export const useInit = (_store, routeObj) => {
4228
Global.onpopstate=browserHistoryBtnClicked
4329
},[_store,routeObj])
4430
}
31+
32+
exportconstholder=1

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp