I am learning ReactJs. I want to use one componemt inside the other component. I looked this, this and this and other sources, tried to apply the solutions, but they did not help me...
My list.html contains:
<body>
...
<div id="filtered_list"></div>
<script src="built/test.js"></script>
<script src="built/filteredList.js"></script>
</body>
test.js:
'use strict';
const React = require('react');
const ReactDOM = require('react-dom');
const client = require('./client');
class Test extends React.Component {
constructor(props) {
super(props);
this.state = {hellomsg: "one"};
this.state.hellomsg = "I cannot get information from the REST. If you can, help me please.";
}
render() {
client({method: 'GET', path: '/hello-world'}).done(response => {
//this.setState({hellomsg: response.entity});
this.state.hellomsg = response.entity;
});
return (
<p>{this.state.hellomsg}</p>
)
}
}
ReactDOM.render(
<Test />,
document.getElementById('test')
)
export default Test;
filteredList.js:
'use strict';
import Test from './Test';
const React = require('react');
const ReactDOM = require('react-dom');
class FilteredListManger extends React.Component {
render() {
return (
<p>Example Text</p> + <Test/>
)
}
}
ReactDOM.render(
<FilteredListManger />,
document.getElementById('filtered_list'))
< Test / > is not rendered, I have white page.
If I remove "import Test from './Test';" and "+ < Test / >" from filteredList.js, I can see "Example Text" text in the page, it's good.
When I open debug mode in Chrome in Sources tab, I do not see errors, if I open Console tab, I see
Uncaught Error: _registerComponent(...): Target container is not a DOM element.
It leads to test.js:
ReactDOM.render(
<Test/>,
document.getElementById('test')
)
I already applied solution from here, so I do not think this is the reason.
All my js files are in /src/main/js.
After webpack builds the project, they are in /src/resources/static/build.
Htmls are in /src/resources/templates.
What should I change here to I can use rendered result of test.js in filteredList.js?