React无状态函数的传参

#1

无状态函数function,传参数时,当少数参数参时
但多个参数时怎么使用es6的…props怎么传的参数,然后在函数中拿到这个props里的key

换种方式问—

function Input({ label, name, value, ...props }, { defaultTheme }) {
  const { theme, autoFocus, ...rootProps } = props
  return (
    <label
      htmlFor={name}
      children={label || defaultLabel}
      {...rootProps}
    >
    <input
      name={name}
      type="text"
      value={value || ''}
      theme={theme || defaultTheme}
      {...props}
    />
  )}

这个函数在调用时怎么传参

#2

说实话,没有听懂

#3

是不是少了$

#4

再看一下,麻烦了

#5

不是字符串问题,是关于调用的问题,
再看一下,麻烦了

#6
Input({
  label: 'label',
  name: 'name',
  value: 'value',
  theme: 'theme',
  autofocus: true,
  root1: 'root1',
  root2: 'root2',
},{
  defaultTheme: 'defaultTheme',
});
1 Like