Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html ReactJS:如何将道具传递给造型?_Html_Reactjs_Z Index - Fatal编程技术网

Html ReactJS:如何将道具传递给造型?

Html ReactJS:如何将道具传递给造型?,html,reactjs,z-index,Html,Reactjs,Z Index,我有以下部门: <div className='box-default expand' style={{zIndex: props.zindex}}> 当我检查元素时,结果是: <div zindex="0">...</div> 。。。 但它不起作用。难道不是: <div style="z-index: 0">...</div> 。。。 ? 这是父容器: const [zIndex, setZIndexes] = Reac

我有以下部门:

<div className='box-default expand' style={{zIndex: props.zindex}}>

当我检查元素时,结果是:

<div zindex="0">...</div>
。。。
但它不起作用。难道不是:

<div style="z-index: 0">...</div>
。。。
?

这是父容器:

const [zIndex, setZIndexes] = React.useState([0, 1, 2]);

function setZIndex(id) {
    setZIndexes([0, 0, 0]);
    zIndex[id] = 3;
    console.log(zIndex);
}

<div
    zindex={zIndex[0]}
    onClick={()=>setZIndex(0)}
    >
const[zIndex,setzindex]=React.useState([0,1,2]);
函数setZIndex(id){
setzindex([0,0,0]);
zIndex[id]=3;
控制台日志(zIndex);
}
setZIndex(0)}
>

将道具沿组件链传递:

但是父组件应该返回like,而不是div

const ParentComponent = () => {
  ...more code

  return (
    <ChildComponent zindex={zIndex[0]} />
  )
}
constparentcomponent=()=>{
…更多代码
返回(
)
}
和ChildComponent函数应包含:

const ChildComponent = (props) => (
  <div className='box-default expand' style={{zIndex: props.zindex}} >...</div>
)
constchildcomponent=(道具)=>(
...
)
您可以试试这个

const ParentComponent = ({ message }) => {
  const ChildComponent = zindex={zIndex[0]}

  const ChildComponent = (props) => (
  <div className='box-default expand' style={{zIndex: props.zindex}} > 
   {message}</div>
   )
  }
constparentcomponent=({message})=>{
常量ChildComponent=zindex={zindex[0]}
常量ChildComponent=(道具)=>(
{message}
)
}

style={{zIndex:props.zIndex}}
应该可以工作
zindex={zindex[0]}
不会