Javascript React Native中ReactDOM和document.body的等效变量是什么?(世博会)
我正在构建一个Javascript React Native中ReactDOM和document.body的等效变量是什么?(世博会),javascript,reactjs,react-native,react-navigation,expo,Javascript,Reactjs,React Native,React Navigation,Expo,我正在构建一个Modal组件,我在web上用于ReactJS。我将模态作为子对象附加到document.body,并根据需要装载/卸载 这是图表(Stephen Grider的Udemy在线课程) 我的问题是React Native中没有ReactDOM或document.body。这是我的modal.py import React, { Component } from 'react'; import ReactDOM from 'react-dom'; import { store } f
Modal
组件,我在web上用于ReactJS。我将模态
作为子对象附加到document.body
,并根据需要装载/卸载
这是图表(Stephen Grider的Udemy在线课程)
我的问题是React Native中没有ReactDOM或document.body。这是我的modal.py
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import { store } from '../store';
import { Provider } from 'react-redux';
class Modal extends Component {
comoponentDidMount() {
this.modalTarget = document.createElement('div');
this.modalTarget.className = 'modal';
document.body.appendChild(this.modalTarget);
this._render();
}
_render() {
ReactDOM.render(
<Provider store={store}>
<div>{this.props.children}</div>
</Provider>,
this.modalTarget
);
}
componentWillUpdate() {
this._render();
}
componentWillUnmount() {
ReactDOM.unmountComponentAtNode(this.modalTarget);
document.body.removeChild(this.modalTarget);
}
render() {
return <noscript />;
}
}
import React,{Component}来自'React';
从“react dom”导入react dom;
从“../store”导入{store};
从'react redux'导入{Provider};
类模态扩展组件{
comoponentDidMount(){
this.modalTarget=document.createElement('div');
this.modalTarget.className='modal';
document.body.appendChild(this.modalTarget);
这个;
}
_render(){
ReactDOM.render(
{this.props.children}
,
这是modalTarget
);
}
componentWillUpdate(){
这个;
}
组件将卸载(){
ReactDOM.unmountComponentAtNode(this.modalTarget);
document.body.removeChild(this.modalTarget);
}
render(){
返回;
}
}
我正在使用Expo,默认情况下它正在加载App.js!而且没有document.body和ReactDOM。我怎样才能解决这个问题 我们在react native中没有任何DOM。您应该创建一个模态组件,并将其导入到要使用的其他组件中。你的模态的位置必须是绝对的,为了显示模态,你可以给它传递一个道具 您可以使用react native model: 或者由这样的人创建的任何其他模态:
我不想让modal通过CSS从屏幕上定位。我必须处理z-index来弹出模态。我的方法是制作一个身体的孩子,这样它就解决了CSS问题。另外,组件上的假模态调用连接到主体的模态。谢谢您的回答。谢谢你花时间解决我的问题