admin管理员组文章数量:1426101
I want to seperate my rendering of a class in another class and just call the rendering. Do you know how to do this in React Native? Would be great if you can help me out here.
Thanks a lot
Albo
I want to seperate my rendering of a class in another class and just call the rendering. Do you know how to do this in React Native? Would be great if you can help me out here.
Thanks a lot
Albo
Share Improve this question asked Jul 7, 2016 at 5:05 NullPointerNullPointer 1,3292 gold badges12 silver badges20 bronze badges 1- I just wanted to seperate rendering and logic. For example you have a class Home which has business logic and rendering for your view. I want to seperate business logic in one class and rendering of your view in another class. Question now clear? Sorry for that... – NullPointer Commented Jul 7, 2016 at 5:20
3 Answers
Reset to default 3Got it!
You have to write a Class like this for example:
export default class HomeRender extends Component {
constructor(props){
super(props);
}
render() {
return (
<View>
<Text>
Hi
</Text>
</View>
);
}
}
module.exports = HomeRender;
After that you have simple to do the following in your class to call the render function from HomeRender:
var Home = require('./app/ponents/home/HomeRender');
...
render() {
<View>
<Home />
</View>
}
...
Calling render from another class is not good practice. Instead create a new ponent class and import that class in your view. It will render.
This is not a good practise man, in react-native you should always import your ponent and insert it wherever you want like this:
Import your render file which you want like this:
var Home = require('./app/ponents/home/HomeRender');
Again, wherever yo want to import that ponent which consists certain view you can render inside your specific like this:
render() {
<View>
your wish ponent.... <Home/>
</View>
}
This will ease your work in navigation part as well as to render your ponents which return view in wherever you want. Also, you should follow official documentation of react-native as well: https://facebook.github.io/react-native/docs/tutorial.html
本文标签: javascriptCall render from different class in React NativeStack Overflow
版权声明:本文标题:javascript - Call render from different class in React Native - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745407996a2657335.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论