Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixbug ref in react version 16 above #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/ImageListRender.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ import ReactDom from 'react-dom'
import Viewer from 'viewerjs'
require('viewerjs/dist/viewer.min.css')
class ImageListRender extends PureComponent {
constructor(props) {
super(props);
// create a ref to store the textInput DOM element
this.imageListWrapper = React.createRef();
}
render() {
const {imageUrls} = this.props;
return (<div style={{display:'none'}} ref="imageListWrapper">
return (<div style={{display:'none'}} ref={this.imageListWrapper}>
{
imageUrls.map((url, index) => {
return <img src={url} key={index} style={{display: 'none'}}/>
Expand Down Expand Up @@ -40,7 +45,7 @@ class ImageListRender extends PureComponent {
}
};
/*因为Viewer接受的参数必须是一个图片容器或者是一个图片元素,其他元素初始化会被中断*/
this.viewer = new Viewer(ReactDom.findDOMNode(this.refs.imageListWrapper), options);
this.viewer = new Viewer(ReactDom.findDOMNode(this.textInput.current), options);
this.viewer.view(index);
}
componentWillUnmount() {
Expand Down