You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.
//reducer to change open-close flag and message
const initState = {
open:false,
message:""
}
const snackBarReducer =(state = initState,action)=>{
switch(action.type){
case snackBarActionType.ACTION_OPEN:
return {...state,...action.payload}
case snackBarActionType.ACTION_CLOSE:
return initState
default :
return state
}
}
//first level router
const routes = {
'/': () => <Login />,
'/Main': () => <Main />,
'/Register*':() => <Register /> //this use * to match second level router!!!!!!!!!
};
function App() {
const routeResults = useRoutes(routes) //use hookrouter
const dispatch = useDispatch();
const snackflag = useSelector(state=>state.snackBarReducer) //react-redux to controll public snackbar open-close flag and snackbar message
return (
<div id ='App'>
{routeResults || <NotFind/>} //use router to controll which page to show
<Snackbar //snackbar(component in material-ui,like Toast in Android)
autoHideDuration = {1000}
message={snackflag.message} //message property to controll message to show
open= {snackflag.open} //open property to cotroll open-close flag
onClose = {()=>dispatch({type:snackBarActionType.ACTION_CLOSE,payload:{}})}
>
</Snackbar>
</div>
);
}
//second level router in Register page
const a = {
'/' :()=><MailRegister/>, //error occur in this page
'/PasswordSet' :()=> <PasswordSet/>,
'/BaseInfo' :()=> <BaseInfo/>
}
//code in MailRegister
<button className ={`${classes.btnBase} ${classes.validateBtnCss}`}
onClick={()=>**sendValidate()**}>Sendvalidata</button>
sendValidate method:
const sendValidate = ()=>{
//send request to behind and show message
validataSend(mailBox).then((res)=>{
//change value of snackBarReducer to open snackbar
dispatch({type:snackBarActionType.ACTION_OPEN,payload:{open:true,message:res.data.message}})
})
}
at this time,error occur,when snackbar show,the content in inputbox was cleared,not one inputbox but all inputbox,
so i think this page was re-render,but at this page ,i do not use content of snackBarReducer, i guess, first level router
and current path is different??? i am confuse,please help me,thank you,sorry to disturb you。
Below is the page change of mine:
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
at this time,error occur,when snackbar show,the content in inputbox was cleared,not one inputbox but all inputbox,
so i think this page was re-render,but at this page ,i do not use content of snackBarReducer, i guess, first level router
Below is the page change of mine:
![image](https://user-images.githubusercontent.com/38390347/135118334-666df1a1-4daa-4c50-ae6b-d0082a027485.png)
![image](https://user-images.githubusercontent.com/38390347/135118512-180d7682-55f0-4010-b22d-c7b88af6e2db.png)
The text was updated successfully, but these errors were encountered: