Skip to content

Instantly share code, notes, and snippets.

@domtalbot
Created October 13, 2017 13:13
Show Gist options
  • Save domtalbot/7c98982e3d1a8226e1cee30c128bcc4b to your computer and use it in GitHub Desktop.
Save domtalbot/7c98982e3d1a8226e1cee30c128bcc4b to your computer and use it in GitHub Desktop.
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>
);
}
}
@domtalbot
Copy link
Author

fieldValueSelected is always a string on a preview element whereas my control it is an object

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment