React Transferring Props except one

前端 未结 5 1973
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-23 13:05

React suggests to Transfer Props. Neat!

How can I transfert all but one?

render: function(){
  return (

        
5条回答
  •  萌比男神i
    2020-12-23 13:59

    What you need to do is to create a copy of the props object and delete the key(s) you don't want. The easiest would be to use omit from lodash but you could also write a bit of code for this (create a new object that has all the keys of props except for one).

    With omit (a few options at the top, depending on what package you import/ES flavor you use):

    const omit = require('lodash.omit');
    //const omit = require('lodash/omit');
    //import { omit } from 'lodash';
    
    ...
    render() {
        const newProps = omit(this.props, 'one');
        return ;
    }
    

提交回复
热议问题