zoukankan      html  css  js  c++  java
  • this.props.children 踩坑

    问题:

    import React from 'react';
    import ReactDOM from 'react-dom';
    // import {BrowerRouter as Router,Switch,Route,Link} from '';
    
    // import Home from 'page/home/index.jsx';
    class A extends React.Component {
    	constructor (props){
    		super	(props)
    
    	}
    	render(){
    		return <div>component A</div>
    
    	}
    }
    class B extends React.Component {
    	constructor (props){
    		super	(props)
    	}
    	render(){
    		return <div>component B</div>
    
    	}
    }
    //容器
    class Wrapper extends React.Component {
    	constructor(props){
    		super	(props)
    	}
    
    	render() {
    		return (
    			<div>
    				{this.props.children}
    		 </div>
    		)
    
    	}
    }
    
    ReactDOM.render(
    	<Wrapper>
    		<A/>
    		<B/>
    	<Wrapper/>,
    	document.getElementById('app')
    )
    

    报错:

    排除了一下错,原来是因为:

    wrapper的闭合标签写错了。

    正确的写法应该是:

    import React from 'react';
    import ReactDOM from 'react-dom';
    // import {BrowerRouter as Router,Switch,Route,Link} from '';
    
    // import Home from 'page/home/index.jsx';
    class A extends React.Component {
        constructor (props){
            super    (props)
    
        }
        render(){
            return <div>component A</div>
    
        }
    }
    class B extends React.Component {
        constructor (props){
            super    (props)
        }
        render(){
            return <div>component B</div>
    
        }
    }
    //容器
    class Wrapper extends React.Component {
        constructor(props){
            super    (props)
        }
    
        render() {
            return (
                <div>
                    {this.props.children}
             </div>
            )
    
        }
    }
    
    ReactDOM.render(
        <Wrapper>
            <A/>
            <B/>
        </Wrapper>,
        document.getElementById('app')
    )
  • 相关阅读:
    Tableau如何绘制堆叠柱状图
    Tableau如何绘制多边形地图
    Tableau如何绘制凹凸图
    数据库备份策略设计
    MySQL数据库如何实现增量备份
    Tableau如何绘制瀑布图
    创建.net core ef项目
    asp.net core的ef的连接字符串
    sqlserver的varchar nvarchar区别
    jq的ajax请求写法
  • 原文地址:https://www.cnblogs.com/ipoodle/p/9690155.html
Copyright © 2011-2022 走看看