mirror of https://github.com/embarklabs/embark.git
Move from props to state
This commit is contained in:
parent
3339d27ee7
commit
31cfc7bdeb
|
@ -1,11 +1,11 @@
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
class ApplicationPreviewContainer extends React.Component {
|
class ApplicationPreviewContainer extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
previewUrl: props.previewUrl || 'http://localhost:8000'
|
previewUrl: 'http://localhost:8000'
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ class ApplicationPreviewContainer extends React.Component {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className="input-group mb-3">
|
<div className="input-group mb-3">
|
||||||
<input type="text" className="form-control" placeholder="URL" ref={(input) => this.locationInput = input} value={this.props.previewUrl} />
|
<input type="text" className="form-control" placeholder="URL" value={this.state.previewUrl} onChange={(e) => this.handlePreviewUrlChange(e)} />
|
||||||
<div className="input-group-append">
|
<div className="input-group-append">
|
||||||
<button className="btn btn-outline-secondary" type="button" onClick={(e) => this.handlePreviewGo(e)}>Go</button>
|
<button className="btn btn-outline-secondary" type="button" onClick={(e) => this.handlePreviewGo(e)}>Go</button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -23,6 +23,10 @@ class ApplicationPreviewContainer extends React.Component {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handlePreviewUrlChange(ev) {
|
||||||
|
this.setState({previewUrl: ev.target.value});
|
||||||
|
}
|
||||||
|
|
||||||
handlePreviewChange(ev) {
|
handlePreviewChange(ev) {
|
||||||
try {
|
try {
|
||||||
let url = ev.target.contentWindow.location.toString();
|
let url = ev.target.contentWindow.location.toString();
|
||||||
|
@ -33,13 +37,9 @@ class ApplicationPreviewContainer extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
handlePreviewGo() {
|
handlePreviewGo() {
|
||||||
this.previewIframe.src = this.locationInput.value;
|
this.previewIframe.src = this.previewUrl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ApplicationPreviewContainer.propTypes = {
|
|
||||||
previewUrl: PropTypes.string
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ApplicationPreviewContainer;
|
export default ApplicationPreviewContainer;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue