Open dlrandy opened 5 years ago
https://github.com/Pau1fitz/react-interview
function IOCComponent(WrappedComponent){ class Enhancer extends WrappedComponent { constructor(props){ super(props); } state = { input: '' } onInput = (e) => { this.setState({input: e.target.value}) } render() { return <div> {super.render()} </div> } } return Enhancer; } let cache = null; function PPComponent( WrappedComponent ){ class HOCComponent extends React.Component { state = { loading: false, apiData: null, }; componentDidMount(){ if(cache){ this.setState({ apiData: cache }); } fetch('/request-api') .then(res => res.json()) .then(data => { cache = data; this.setState({ apiData: cache }) }) } render(){ const { apiData } = this.state; return <WrappedComponent {...this.props} apiData={apiData} /> } } return HOCComponent; } function IOCComponent (WrappedComponent) { class HOCComponent extends WrappedComponent { constructor(props){ super(props); } shouldComponentUpdate(nextProps, nextState) { const { propsKey } = this.props; const { key } = this.state; if(nextProps.propsKey === propsKey || nextState.key === key ){ return false; } return true; } render() { return super.render(); } } return HOCComponent; } function PPComponent (WrappedComponent) { class HOCComponent extends React.Component { constructor(props){ super(props); } render(){ const { children } = this.props; return <WrappedComponent> { React.Children.toArray(children).sort() } </WrappedComponent>; } } return HOCComponent; }
https://www.edureka.co/blog/interview-questions/react-interview-questions/
https://tylermcginnis.com/react-interview-questions/
https://www.toptal.com/react/interview-questions
https://github.com/Pau1fitz/react-interview