JavaScript for WordPress › Forums › Gutenberg Development › render() function in component class error
- This topic has 2 replies, 2 voices, and was last updated 6 years, 1 month ago by
ldecoker.
Viewing 3 posts - 1 through 3 (of 3 total)
-
AuthorPosts
-
September 6, 2019 at 3:30 pm #117333
ldecoker
ParticipantHello!,
Below the code for my component:
class PodcastDropDownList extends Component { constructor(props) { super(...arguments); this.props = props; this.state = { podcastThemes: [], loading: false } } componentDidMount() { this.setState({ loading: true, }); api.getPodcastthemes() .then(({ data = {} } = {}) => { this.setState({ podcastThemes: data, loading: false }); }); } render() { return( <div> <label htmlFor="themes">Select your podcast theme : </label> <select name="themes" id="podcastThemes" > { (this.state.loading) ? (<option value="">loading ... </option>) : ( Object.keys(this.state.podcastThemes).map( key => ( <option key={key} value={this.state.podcastThemes[key].id}>{this.state.podcastThemes[key].title}</option> ) ) ) } </select> </div> ); } } export default compose([ withSelect( ( select, { slug } ) => { const { getCurrentPost } = select( 'core/editor' ); const { getTaxonomy } = select( 'core' ); const taxonomy = getTaxonomy( slug ); return { terms: taxonomy ? select( 'core/editor' ).getEditedPostAttribute( taxonomy.rest_base ) : [], taxonomy, }; } ), ])(PodcastDropDownList);I got the following compilation error:
ERROR in ./metabox/podcasttheme/components/PodcastDropDownList.js Module build failed: SyntaxError: Unexpected token (42:3) 40 | render() { 41 | return( > 42 | <div> | ^I do not understand this. Any idea?
Thx!
September 6, 2019 at 5:20 pm #117368Zac Gordon
KeymasterOkay, first thing I want to check is that this isn’t due to a missing babel config setup. If you just return some very simple React, like a p tag with text does it work or give the same error. Also, depending on what Boilerplate you started with, do you have a .babelrc file?
September 9, 2019 at 6:56 am #117538ldecoker
ParticipantIndeed this was a missing babel config. I forgot to install the “@wordpress/babel-preset-default”.
thx !!
-
AuthorPosts
Viewing 3 posts - 1 through 3 (of 3 total)
- You must be logged in to reply to this topic.
