프로그래밍 정보공유

함수형 컴포넌트 생성과 props로 함수 파라미터 넘기기

student513 2020. 7. 6. 10:47
const Question = (props) => {
    const search = props.data.filter(
        (qna) => {
            return qna.question.indexOf(props.keyword) > -1;
        }
    )
    console.log(search)
    return (
        <Accordion
            sections={search}
            activeSections={props.activeSections}
            touchableComponent={TouchableOpacity}
            duration={0}
            onChange={props.updateSections}
            scrollEnabled={false}
            style={{ borderWidth: 0 }}
            renderHeader={props.renderHeader}
            renderContent={props.renderContent}
            keyExtractor={item => item.id.toString()}
        />
    )
}

class CustomerHelp extends Component {
    constructor(props) {
        super(props)
        this.state = {
            faqs: [],
            selectedCategoryIndex: 0,
            activeSections: [],
            keyword:'',
        }
    }
    _renderHeader=()=>{}
    _renderContent=()=>{}
    _updateSection=()={}
    render(){
    	return(
    	<Question 
        	data={flatQna} 
        	keyword={this.state.keyword}
        	renderHeader={this._renderHeader} 
        	renderContent={this._renderContent}
        	activeSections={this.state.activeSections}
        	updateSections={this._updateSections}
        />
        
        )
    }
}
 

React: Passing down props to functional components

I have a seemingly trivial question about props and functional components. Basically, I have a container component which renders a Modal component upon state change which is triggered by user click...

stackoverflow.com