Created
October 13, 2017 13:13
-
-
Save domtalbot/7c98982e3d1a8226e1cee30c128bcc4b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { PropTypes, Component } from 'react'; | |
import { connect } from 'react-redux'; | |
import { Map } from 'immutable'; | |
import CMS from 'netlify-cms'; | |
export default class DynamicPreview extends Component { | |
static propTypes = { | |
onChange: PropTypes.func.isRequired, | |
onAddAsset: PropTypes.func.isRequired, | |
onRemoveAsset: PropTypes.func.isRequired, | |
getAsset: PropTypes.func.isRequired, | |
// value: PropTypes.object, | |
field: PropTypes.node, | |
forID: PropTypes.string, | |
dynamicWidgets: PropTypes.object | |
}; | |
constructor(props) { | |
super(props); | |
const fieldValue = this.props.value && Map.isMap(this.props.value) ? | |
this.props.value.get(this.props.field.get('name')) : | |
this.props.value; | |
console.log(this.props.value); | |
} | |
render() { | |
const { field, value, forID, onChange, onAddAsset, onRemoveAsset, getAsset, dynamicWidgets } = this.props; | |
const name = field.get('name'); | |
const selectedName = `${ field.get('name') }_selected`; | |
const fieldValue = value && Map.isMap(value) ? | |
value.get(name) : | |
value; | |
const fieldValueSelected = value && Map.isMap(value) ? | |
value.get(selectedName) : | |
value; | |
return ( | |
<div>{(field && field.get('fields')) || null}</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
fieldValueSelected is always a string on a preview element whereas my control it is an object