shallow rendering 사용하지 않는 이유
import React from 'react';
import { CSSTransition } from 'react-transition-group';
function Fade({ children, ...props }) {
return (
<CSSTransition {...props} timeout={1000} className="fade">
{children}
</CSSTransition>
);
}
class HiddenMessage extends React.Component {
static defaultProps = { initialShow: false };
state = { show: this.props.initialShow };
toggle = () => {
this.setState(({ show }) => ({ show: !show }));
};
render() {
return (
<div>
<button onClick={this.toggle}>Toggle</button>
<Fade in={this.state.show}>
<div>Hello world</div>
</Fade>
</div>
);
}
}
export { HiddenMessage };
shallow(<HiddenMessage />);Last updated
Was this helpful?