React面試題


1.ReactJS中渲染根組件的方式以及注意事項

答案:ReactDOM.render(A,B);將A渲染到B指定的容器中

注意事項:

       不允許一次渲染多個標簽,但是可以放在同一個頂層標簽

        每一個標記都要有對應的結束

 

2.ReactJS中父子組件通信的方式

(1)父與子通信

借助於屬性   往下傳值

傳值:

<son  myName="123"></son>

接收值:

this.props.myName

(2)子與父通信

通過屬性傳遞有參數的方法,讓子組件調用時傳值

①定義有參數的方法

rcvMsg(msg){}

②傳遞給子組件

<son  funcRcv={this.rcMsg}></son>

③子組件來調用

This.props.funcRcv(123)

 

3.如何在組件渲染時調用組件內部嵌套的子組件

This.props.children

 

4.組件的生命周期

mount:

    componentWillMount

    componentDidMount

update

    componentWillUpdate

    componentDidUpdate

    componentWillReceiveProps

unmount:

   componentWillUnmount

 

5.在組件渲染時  實現判斷和循環功能

(1)判斷

短路邏輯

{  expression  && <Any></Any> }

(2)循環

遍歷集合

this.state.list

      .map((value,index)=>{   

         return <li  key={index}>

                         {value}

                    </li>

    })

 

6.描述ReactNative的特點和開發理念

ReactNative是實現原生開發的框架

可以使用react的語法和js來編寫

 

開發理念:

  Learn  once,write anywhere 

 

7.react中如何處理網絡通信的

fetch(url).then((response)=>response.json()).then((result)=>{ })

 

8.react中循環創建多個組件時指定key的作用?

在dom變化時,快速定位元素 提升更新效率

 

9.react的生態圈(技術棧)中有哪些常見技術?

reactjs、reactNative、react360、flux、redux、ssr、reactNavigation

 

10.基於reactNative的reactNavigation中的基礎用法?

跳轉:

     this.props.navigation.navigate()

傳參:

     this.props.navigation.navigate('detail',{id:10})

     this.props.navigation.getParam('id');

 

11.reactNative中如何實現高性能列表

import { FlatList }  from 'react-native'

 

showItem=(info)=>{

     return ***

}

 

<FlatList   data={[1,2,3]}  renderItem="showItem">

 

</FlatList>

 

12.reactNative中如何完成自定義布局

可以使用c3中的flexbox

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM