简体   繁体   中英

How to create dynamic React Native components

I want the button to be dynamically created and used when the click event occurs. The button's creation location should be created 10px to the right of the existing button. Ask for help from great and kind friends. it is my code

import React, { Component } from 'react'
import { Button } from 'react-native'
const Test = () => { 
    return( 
        <Button title='test' onPress={<Button title='test1'/>}/> 
    ) 
} 
export default Test 

or

import React, { Component } from 'react'
import { Button } from 'react-native'
const Test = () => { 
    return( 
        <Button title='test' onPress={ButtonRender}/> 
    ) 
}
const ButtonRender =():any=>{
    return <Button title='test1'/>
}
export default Test 

I have a problem. It is not created Button. I need help

Create a State variable buttonClicked=false

<button onclick={() => setState({buttonClicked=true})}/>
{state.buttonClicked?<button></button>:null}

and update state when button clicked

Please set the style for that created button

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM