두 가지 구성 요소가 있는데, 예를 들어 componentA
과 componentB
이라고합시다. 두 구성 요소 모두 .gif
파일을 가져 오는데, image.gif
이라고 가정 해 보겠습니다. image.gif
은 루프되지 않으므로 업데이트되지 않은 경우에만 재생해야합니다.GIF 파일을 다른 구성 요소가 반응에서 사용할 때 다시로드하지 못하도록합니다.
처음에는 componentA
은 image.gif
이지만, componentB
은 렌더링하지 않습니다. 따라서 image.gif
안에 componentA
한 번 재생됩니다. componentB
안에 image.gif
을 렌더링하면 componentA 안에 image.gif
이 다시 재생됩니다. 이는 원하지 않습니다.
할 수 있습니까? 감사!
편집 : 재현에 대한 몇 가지 간단한 코드 : './image.gif'
로export default class componentA extends React.PureComponent {
render() {
return (
<div>
<img src={image} />
</div>
);
}
}
Component B
이미지 가져 오기 './image.gif'로
Component A
이미지 가져 오기
export default class componentA extends React.PureComponent {
render() {
return (
<div>
{this.props.show ? <img src={image} /> : null}
</div>
);
}
}
App
import componentA from './componentA.react'
import componentB from './componentB.react'
export default class App extends React.Component {
componentWillMount() {
this.setState({
show: false,
});
}
componentDidMount() {
// ...or some moment when the App thinks componentB should update
this.setTimeout(() => {
this.setState({
show: true,
});
}, 4000);
}
render() {
return (
<componentA />
<componentB show={this.state.show} />
);
}
}
하면, 몇 가지 코드를 제공시겠습니까 우린 당신을 도울 수 있어요? componentA와 B는 어떻게 구성됩니까? – 3Dos
일부 샘플 추가 – Theogry