1

i create a mask and have here some different field types so i think im better to create a element and use it later in the app with so im trying with export and import but i have not thaht success i wish.

My plan is give a array with fields and one with selected fields to my component(this works, i see it in the state) and get the element back

Currently my component gives a array back but i want the html element which is usally genereated by render

    import React, { Component } from 'react'
import ReactDOM from 'react-dom';
class Selbox extends Component {

     constructor(props) {
    super(props);
       this.state = {
        fields : JSON.parse(props.fields),
        selectedval : JSON.parse(props.sel)
        };          
   }
  render() {
     const select_box = this.state.fields.map((ck, index) =><div key={ck.id} className="checkbox"><label><input type="checkbox"   checked={this.state.selectedval.indexOf(ck.id) != -1 ? true: false} value={ck.id}/>{ck.name}</label></div>);          
    return ({select_box})
  }
}


export default selbox

And i want import it in

import React from 'react';
import ReactDOM from 'react-dom';
import selbox from './selbox';

class Liste extends React.Component {
 constructor(props) {
    super(props);
       this.state = {};
  }

 componentDidMount(){}

 render() {
    return(<selbox sel='["4","6"]'  fields='[{"name":"field1","id":"1"},{"name":"field2","id":"2"},{"name":"field3","id":"3"},{"name":"field4","id":"4"},{"name":"field5","id":"5"}]' />);
  }
}


ReactDOM.render(
  <Liste />,
  document.getElementById('gb_28338201')
);
StefanBD
  • 137
  • 9
  • first you cannot return an array ```return ({select_box})``` second `sel` and `fields` props are clearly there, how are you not seeing it? third use capital on first letter of every component ```selbox = Selbox``` thats how react works – Rei Dien Sep 27 '17 at 11:23
  • 1
    sorry im not helping – Rei Dien Sep 27 '17 at 11:34
  • you did with the first letter, this was one problem, gime a moment i will edit the question – StefanBD Sep 27 '17 at 11:37
  • {select_box} is the solution, i had to put the lement into a div – StefanBD Sep 27 '17 at 11:44

0 Answers0