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

Commit864a26e

Browse files
committed
setup cond rendering route
1 parent9c530c9 commit864a26e

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

‎web-app/src/Routes.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import*asReactfrom'react'
22
import*asCRfrom'typings'
3+
importNewPagefrom'./components/New'
4+
importContinuePagefrom'./components/Continue'
5+
importCondfrom'./components/Cond'
36

47
interfaceReceivedEvent{
58
data:CR.Action
@@ -24,8 +27,16 @@ const Routes = () => {
2427
window.removeEventListener(listener,handleEvent)
2528
}
2629
})
30+
2731
return(
28-
<div>State:{JSON.stringify(state)}</div>
32+
<div>
33+
<Condstate={state}path="SelectTutorial.NewTutorial">
34+
<NewPageonNew={()=>console.log('new!')}/>
35+
</Cond>
36+
<Condstate={state}path="SelectTutorial.ContinueTutorial">
37+
<ContinuePageonContinue={()=>console.log('continue!')}tutorials={[]}/>
38+
</Cond>
39+
</div>
2940
)
3041
}
3142

‎web-app/src/components/Cond/index.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import*asReactfrom'react'
2+
import{stateMatch}from'./utils/state'
3+
4+
interfaceProps{
5+
state:any
6+
path:string
7+
children:React.ReactElement
8+
}
9+
10+
constCond=(props:Props)=>{
11+
if(!stateMatch(props.state,props.path)){
12+
returnnull
13+
}
14+
returnprops.children
15+
}
16+
17+
exportdefaultCond
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
exportfunctionstateMatch(state:any,statePath:string){
2+
letcurrent=state
3+
letpaths=statePath.split('.')
4+
try{
5+
for(constpofpaths){
6+
current=current[p]
7+
}
8+
}catch(error){
9+
returnfalse
10+
}
11+
returncurrent!==undefined
12+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp