我正在使用React 360创建一个VR应用程序。我想要做的是最终创建一个应用程序,如这里所示的Facebook VR multi surface example。我正在使用该示例的代码,并尝试将其适合我的应用程序。但是,我在React组件的以下初始化过程中遇到了问题。
我有一个带有以下代码index.js的react-360应用程序
import React from 'react';
import connect from './Store';
import {
asset,
AppRegistry,
StyleSheet,
Text,
View,
VrButton,
} from 'react-360';
import Entity from 'Entity';
const ModelView = props => {
*********** Problem **************
Why are my props undefined if I am declaring it in the wrapper?
**********************************
return (
<Entity
style={{transform: [{scaleX: 1.25}, {scaleY: 1.25}]}}
source={{obj: asset(`${props.planetName}.obj`), mtl: asset(`${props.planetName}.mtl`)}}
/>
);
};
const ConnectedModelView = connect(ModelView);
export default ConnectedModelView;
AppRegistry.registerComponent('ModelView', () => ModelView);从上面的代码中,我对ModelView的支持不应该是未定义的。在初始化时,它的值应该是earth。
这些属性应该在Store.js中初始化。代码如下:
import React from 'react';
const State = {
planetName: 'earth'
};
const listeners = new Set();
export default function connect(Component) {
return class Wrapper extends React.Component {
state = {
planetName: State.planetName
};
_listener = () => {
this.setState({
planetName: State.planetName
});
};
componentDidMount() {
listeners.add(this._listener);
}
componentWillUnmount() {
listeners.delete(this._listener);
}
render() {
return (
<Component
{...this.props}
planetName={this.state.planetName}
/>
);
}
};
}从facebook代码中获取一个页面,我正在做的是通过Store.connect方法初始化模型视图。这个方法在我通过State.planetName设置道具的ModelView周围创建了一个包装器。然而,我一直没有定义,我不知道为什么。我已经将代码的每一部分都硬编码为State.planetName的地球值,但它仍然是未定义的。道具没有被设置为我想要的值,我不确定为什么。有没有人能帮我解释一下为什么会这样?如果能帮上忙我会很感激。
发布于 2018-12-22 01:42:13
看起来您呈现的是ModelView而不是ConnectedModelView。
https://stackoverflow.com/questions/53888800
复制相似问题