score:1
It's a little late, but I just stumbled across the same problem.
You can modify your code to create a ref to the div, which can then be treated as a normal HTML-element. First, create the div:
constructor(props) {
super(props);
this.container = document.createElement('div');
this.reference = React.createRef();
}
Then, you add the ref to the correct div:
render() {
return (
<div ref={this.reference}>
</div>
)
}
You can append whenever you like, but I'd do it after the component mount:
componentDidMount()
{
this.reference.current.appendChild(this.container());
}
See here for an implementation with functional components
score:2
ReactElements
are not to be confused with DOM Elements.
You can create React Element through React.createElement.
this.container = React.createElement('div');
Source: stackoverflow.com
Related Query
- Render HTMLDivElement in React
- React onClick function fires on render
- Render HTML string as real HTML in a React component
- Make React useEffect hook not run on initial render
- Is it possible to return empty in react render function?
- Is it possible to use if...else... statement in React render function?
- Objects are not valid as a React child. If you meant to render a collection of children, use an array instead
- How to render react components by using map and join?
- How to create dynamic href in react render function?
- When should you use render and shallow in Enzyme / React tests?
- React doesn't render autocomplete off
- How to render a multi-line text string in React
- Access React Context outside of render function
- Functions are not valid as a React child. This may happen if you return a Component instead of from render
- How can I render repeating React elements?
- Rendering React components with promises inside the render method
- react router difference between component and render
- How can I render HTML from another file in a React component?
- Tag Error: React JSX Style Tag Error on Render
- Sort an array of objects in React and render them
- Is there a way to render multiple React components in the React.render() function?
- Jest Enzyme test a React component that returns null in render method
- How do I render Markdown from a React component?
- onClick doesn't render new react component.
- React fetch data in server before render
- React JSX, how to render text with a single quote? Example <p>I've</p>
- How to render rectangles in a D3 grouped bar chart using React Faux DOM?
- For loop in react render method
- How to focus something on next render with React Hooks
- React component render is called multiple times when pushing new URL
More Query from same tag
- How to change Material UI tab button width
- How to pass props to child component based on dynamic route
- why Higher-Order Components is components?
- Simple Reactjs app without using npm and server?
- importing a state value from react class component
- Filter array by axios get results
- How can I remove HTML markup from strings in state data?
- How can I fix tooltip with overflow-x and overflow-y?
- Is it possible to limit the formatting of a string in Typescript (or ESLint?)
- State element does not appear on react simple map with react-tooltip
- React Bootstrap Typeahead children onclick
- Why do I get undefined when mapping and passing through a prop (ReactJS)
- ERROR #98123 WEBPACK when running `npm run develop`
- Redux action must be plain objects
- React-Redux: mapping an array of objects and initializing a component from each
- Delete specific object with id
- How do I customise themes in Carbon Design System?
- Accessing JSON from public folder in ReactApp
- Typescript: fetch file from API and read it's original filename
- How to compose fragments from an array of relay containers?
- css loader not working
- ReactJS + Material-UI: How to set current date as default value using Material-UI's <DatePicker>?
- Do I have to set every properties initial value in useState?
- React get updated props after submit and dispatch
- How can I wait until request to Firebase completes and then render app in ReactJS?
- Navigation bar displayed incorrectly when scrolling and in mobile view
- How to update React Component props during unit tests?
- No overload matches this call. in React Stripe PaymentElement
- ReactJS: Data from Express displays as numbers instead of JSON
- session flush automaically in express-session