Javascript React中的渲染方法是否总是必需的?
我通过React学习,我认为React中的Javascript React中的渲染方法是否总是必需的?,javascript,reactjs,components,Javascript,Reactjs,Components,我通过React学习,我认为React中的render方法是必须的,但我看到了以下组件: export const GoogleButton = withStyles(theme => ({ root: { height: 55, width: 255, margin: theme.spacing(5, 0, 2), padding: theme.spacing(0, 1), justifyContent: 'start', backgr
render
方法是必须的,但我看到了以下组件:
export const GoogleButton = withStyles(theme => ({
root: {
height: 55,
width: 255,
margin: theme.spacing(5, 0, 2),
padding: theme.spacing(0, 1),
justifyContent: 'start',
background: theme.palette.background.default,
},
startIcon: {
marginRight: 20,
paddingRight: 3,
borderRight: `1px solid ${theme.palette.text.primary}`,
background: 'none',
},
}))(Button);
type AllProps = OwnProps & StateProps & DispatchProps;
export const GoogleLoginButtonPure = ({ isInProgress, login }: AllProps) => {
const handleClick = useCallback(() => login(), [login]);
const { t } = useTranslation();
return (
<GoogleButton
disabled={isInProgress}
onClick={handleClick}
fullWidth
variant="contained"
startIcon={GOOGLE_ICON}
>
{t('login.button')}
</GoogleButton>
);
};
export const GoogleButton=withStyles(主题=>({
根目录:{
身高:55,
宽度:255,
边距:主题。间距(5,0,2),
填充:主题。间距(0,1),
为内容辩护:“开始”,
背景:theme.palete.background.default,
},
startIcon:{
marginRight:20,
paddingRight:3,
borderRight:`1px solid${theme.palete.text.primary}`,
背景:“无”,
},
}))(按钮);
键入AllProps=OwnProps&StateProps&DispatchProps;
export const GoogleLoginButtonPure=({isInProgress,login}:AllProps)=>{
const handleClick=useCallback(()=>login(),[login]);
const{t}=useTranslation();
返回(
{t('login.button')}
);
};
代码运行平稳,但任何人都可以向我解释为什么该组件没有
render
方法?render方法仅在类组件中使用。您的组件是一个函数组件,因此无法使用render方法。这是一个函数组件,它有一个return
语句。请看这里: