最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

React插槽 之React.Children的使用小結(jié)

 更新時間:2026年06月20日 10:26:36   作者:英俊瀟灑美少年  
本文深入解析React.Children API的使用方法,包括map、forEach、count、only等實用功能,通過具體代碼示例展示如何管理和操作props.children,感興趣可以了解一下

React.Children 提供了用于處理 this.props.children 不透明數(shù)據(jù)結(jié)構(gòu)的實用方法。

React.Children.map

React.Children.map(children, function[(thisArg)])

在 children 里的每個直接子節(jié)點上調(diào)用一個函數(shù),并將 this 設(shè)置為 thisArg。如果 children 是一個數(shù)組,它將被遍歷并為數(shù)組中的每個子節(jié)點調(diào)用該函數(shù)。如果子節(jié)點為 null 或是 undefined,則此方法將返回 null 或是 undefined,而不會返回數(shù)組。

如果 children 是一個 Fragment 對象,它將被視為單一子節(jié)點的情況處理,而不會被遍歷。

React.Children.forEach

React.Children.forEach(children, function[(thisArg)])

與 React.Children.map() 類似,但它不會返回一個數(shù)組。

React.Children.count

React.Children.count(children)

返回 children 中的組件總數(shù)量,等同于通過 map 或 forEach 調(diào)用回調(diào)函數(shù)的次數(shù)。

React.Children.only

React.Children.only(children)

驗證 children 是否只有一個子節(jié)點(一個 React 元素),如果有則返回它,否則此方法會拋出錯誤。

注意:

React.Children.only() 不接受 React.Children.map() 的返回值,因為它是一個數(shù)組而并不是 React 元素。

React.Children.map 的用例

import React, {Component} from 'react';
import {connect} from 'react-redux';
import {Steps} from 'antd';
import {setStepWillChange, setConfirmStep} from 'actions/common';
import './index.less';
import Final from 'src/project';
import Temp from '../temp/index';
import Storage from 'fw/util/storage';
import util from 'fw/util/util';
class StepView extends Component {

    componentWillMount() {
        setConfirmStep(this.props.dispatch, this.props.stepSource.length - 3);
    }

    render() {
        let visitFrom = Storage.getSession('visitFrom') || util.getUrlParam('visitFrom');
        console.log('%c ?? 張浩雨: StepView -> render -> React.Children.map ', 'font-size:16px;background-color:#44ce68;color:white;', React.Children.map)
        console.log('%c ?? 張浩雨: StepView -> render -> this.props.children ', 'font-size:16px;background-color:#51e51d;color:black;', this.props.children)
        return (
            <div className="steps-wrap" style={{width: '1200px', margin: '30px auto', backgroundColor: '#FFFFFF'}}>
                <Steps current={this.props.stepIndex} maxDescriptionWidth={this.props.maxDescriptionWidth || 100}>
                    {
                        this.props.stepSource.map((v, i) => {
                            return <Steps.Step key={i} title={v.title}/>;
                        })
                    }
                </Steps>
                {
                    React.Children.map(this.props.children, (child, i) => {
                        return <div style={{display: (i === this.props.stepIndex ? 'block' : 'none')}}>
                            {child}
                        </div>;
                    })
                }
                <div className="step-btn-content" style={{padding:'20px 0'}}>
                    <a type="primary" className="step-btn preview-btn"
                       style={{display: ((this.props.stepIndex > this.props.confirmIndex) || this.props.stepIndex === 0) ? 'none' : 'inline-block'}}
                       onClick={() => {
                           setStepWillChange(this.props.dispatch, this.props.stepIndex - 1);
                       }}>上一步</a>
                    {
                        Final.needTemp && (this.props.needTemp !== false) && this.props.stepIndex <= this.props.confirmIndex &&
                        <Temp temp={this.props.temp} reFull={this.props.reFull} getTemp={this.props.getTemp}/>
                    }
                    {this.props.stepIndex !== this.props.confirmIndex && <a type="primary" className="step-btn next-btn"
                                                                            style={{display: this.props.stepIndex === this.props.confirmIndex + 1 ? 'none' : 'inline-block'}}
                                                                            onClick={() => {
                                                                                setStepWillChange(this.props.dispatch, this.props.stepIndex + 1);
                                                                            }}>下一步</a>}
                    <a type="primary" id="submitStepBtnText" className={visitFrom=='shzww'?'step-btn next-btn shzww-tj':'step-btn next-btn'}
                       style={{display: this.props.stepIndex === this.props.confirmIndex ? 'inline-block' : 'none'}}
                       onClick={() => {
                           setStepWillChange(this.props.dispatch, this.props.stepIndex + 1);
                       }}>提交</a>
                </div>
            </div>
        );
    }
}

export default connect(
    (state) => {
        return {
            stepIndex: state.common.stepIndex,
            confirmIndex: state.common.confirmIndex
        };
    }
)(StepView);

{
     React.Children.map(this.props.children, (child, i) => {
         return <div style={{display: (i === this.props.stepIndex ? 'block' : 'none')}}>
             {child}
         </div>;
     })
 }
//! zhy added 特別納稅調(diào)整相互協(xié)商程序申請
import React, {Component} from 'react';
import StepView from 'biz/components/steps/index';
import Wc,{ylztRender} from 'src/common/wc';
import {setConfirmStep} from 'actions/common';
import {connect} from 'react-redux';
import Sqtx from './Sqtx';
import YlTj from './Yltj';
import { jblRender } from 'biz/components/blzt/jbl';
import {option} from './option';

const stepSource = [
   {
       title: '填寫申請表'
   },
   {
       title: '預(yù)覽提交'
   },
   {
       title: '審核中'
   },
   {
       title: '完成'
   }
];
const constBlzt = {
   swsxMc: option.swsxMc,
   blzt: jblRender
}

class Index extends Component {
   componentDidMount() {
       setConfirmStep(this.props.dispatch, 1);
   }
   
   temp(callback){ //todo 暫存
       let data = this.Sqtx.getWrappedInstance().getTemp();
       let requestData = {
           swsxDm: this.props.swsxDm,
           data: JSON.stringify(data),
           sqxh: this.props.sqxh
       };
       callback(requestData);
   }
   
   getTemp(data){ //todo 獲取暫存
       let tempData = JSON.parse(data.data);
       this.Sqtx.getWrappedInstance().setTemp(tempData);
   }
   render() {
       const {stepIndex, stepWillChangeTo, blztDm} = this.props;
       let temp = true;
       return (
           <div>
               {
                   ylztRender(<StepView stepSource={stepSource} 
                               needTemp={temp} 
                               temp={(callback) => { this.temp(callback)}} 
                               getTemp={(data) => {this.getTemp(data)}}
                              >
                       <Sqtx ref={ref => { this.Sqtx = ref}} 
                           stepIndex={stepIndex} 
                           stepWillChangeTo={stepWillChangeTo} 
                           indexKey={0}
                       />
                       <YlTj ylType="pdf" 
                           stepIndex={stepIndex} 
                           stepWillChangeTo={stepWillChangeTo} 
                           indexKey={1}
                       />
                       <Wc ylComponent={YlTj}
                           constBlzt={constBlzt} 
                           stepIndex={stepIndex} 
                           stepWillChangeTo={stepWillChangeTo} 
                           indexKey={2} 
                           swsx={option.swsxDm} 
                           blzt={blztDm}
                       />
                   </StepView>, YlTj, constBlzt)
               }
           </div>
       );
   }
}

export default connect(state => {
   return {
       stepIndex: state.common.stepIndex,
       stepWillChangeTo: state.common.stepWillChangeTo,
       blztDm: state.common.blztStore.blztDm,
       swsxDm: state.common.swsxDm,
       sqxh: state.common.sqxh,
       area:state.common.area
   };
})(Index);

到此這篇關(guān)于React插槽 之React.Children的使用小結(jié)的文章就介紹到這了,更多相關(guān)React.Children 使用內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • React插槽使用方法

    React插槽使用方法

    本文主要介紹了React插槽使用方法,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-12-12
  • react-native 封裝選擇彈出框示例(試用ios&android)

    react-native 封裝選擇彈出框示例(試用ios&android)

    本篇文章主要介紹了react-native 封裝選擇彈出框示例(試用ios&android),具有一定的參考價值,有興趣的可以了解一下
    2017-07-07
  • react項目使用json-server模擬接口獲取數(shù)據(jù)的操作方法

    react項目使用json-server模擬接口獲取數(shù)據(jù)的操作方法

    文章介紹了如何在React項目中使用json-server模擬接口并獲取數(shù)據(jù),首先安裝json-server,創(chuàng)建JSON格式的數(shù)據(jù)文件,并在package.json中添加啟動命令,啟動服務(wù)后,可以通過指定的路徑獲取模擬的數(shù)據(jù),感興趣的朋友一起看看吧
    2025-11-11
  • React?Hooks useReducer?逃避deps組件渲染次數(shù)增加陷阱

    React?Hooks useReducer?逃避deps組件渲染次數(shù)增加陷阱

    這篇文章主要介紹了React?Hooks?之?useReducer?逃避deps后增加組件渲染次數(shù)的陷阱詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-09-09
  • 使用react實現(xiàn)手機號的數(shù)據(jù)同步顯示功能的示例代碼

    使用react實現(xiàn)手機號的數(shù)據(jù)同步顯示功能的示例代碼

    本篇文章主要介紹了使用react實現(xiàn)手機號的數(shù)據(jù)同步顯示功能的示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-04-04
  • react?hooks中的useState使用要點

    react?hooks中的useState使用要點

    這篇文章主要為大家介紹了react?hooks中的useState使用要點詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-09-09
  • React diff算法原理詳細分析

    React diff算法原理詳細分析

    經(jīng)典的diff算法中,將一棵樹轉(zhuǎn)為另一棵樹的最低時間復(fù)雜度為 O(n^3),其中n為樹種節(jié)點的個數(shù)。假如采用這種diff算法,一個應(yīng)用有1000個節(jié)點的情況下,需要比較十億次才能將dom樹更新完成,顯然這個性能是無法讓人接受的
    2022-11-11
  • 深入理解React與閉包的關(guān)系

    深入理解React與閉包的關(guān)系

    本文將深入探討React與閉包之間的關(guān)系,我們將首先介紹React和閉包的基本概念,然后詳細解釋React組件中如何使用閉包來處理狀態(tài)和作用域的問題,希望通過本文的閱讀,你將對React中閉包的概念有更深入的理解,并能夠在開發(fā)React應(yīng)用時更好地應(yīng)用閉包
    2023-07-07
  • React Native懸浮按鈕組件的示例代碼

    React Native懸浮按鈕組件的示例代碼

    本篇文章主要介紹了React Native懸浮按鈕組件的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起看看吧。
    2018-04-04
  • 詳解在React項目中如何集成和使用web worker

    詳解在React項目中如何集成和使用web worker

    在復(fù)雜的React應(yīng)用中,某些計算密集型或耗時操作可能會阻塞主線程,導(dǎo)致用戶界面出現(xiàn)卡頓或響應(yīng)慢的現(xiàn)象,為了優(yōu)化用戶體驗,可以采用Web Worker來在后臺線程中執(zhí)行這些操作,本文將詳細介紹在React項目中如何集成和使用Web Worker來改善應(yīng)用性能,需要的朋友可以參考下
    2023-12-12

最新評論

全椒县| 洞口县| 呼和浩特市| 南木林县| 鄂伦春自治旗| 汨罗市| 中超| 清新县| 额敏县| 平顺县| 桂东县| 三穗县| 平塘县| 南充市| 高安市| 无锡市| 黄龙县| 遂溪县| 中宁县| 宁安市| 凉城县| 潞城市| 英德市| 红桥区| 颍上县| 当阳市| 寻甸| 交口县| 家居| 玉溪市| 广河县| 和田县| 靖江市| 肥东县| 海林市| 大港区| 庆安县| 贵溪市| 平昌县| 威海市| 紫金县|