更新状态后,react组件不会重新呈现

时间:2020-10-13 12:04:05

标签: javascript reactjs

我有这个React功能组件,我在其中输入了文件。 选择文件后,我假设h1标签中的文本应从 choose filetest,但什么也没发生

  • handleChange函数被触发
  • console.log打印状态。显示:true
  • INSIDE console.log()打印状态。show:true,但不显示字符串测试
import React, { useState } from 'react';

export default ({ selectedFile }) => {
  const [state, setState] = useState({});

  const handleChange = e => {
    console.log('in handleChange');
    setState({ ...state, show: true });
  };
  console.log('My state: ', state);
  return (
    <div className='file-uploader'>
      <input type='file' id='upload' hidden onChange={handleChange} />
      <label htmlFor='upload'>
        {state.show ? <h1> {console.log('INSIDE ', state)} test</h1> : <h1>choose file</h1>}
      </label>
    </div>
  );
};

1 个答案:

答案 0 :(得分:1)

在初始状态下,您需要以下属性select tbf.idFornecedor, tbf.txtNomeResumido, tbf.txtNomeCompleto, tbf.bitHabilitado, sum(case when idDocumentosFornecedoresTitulo = 1 then 1 else 0 end) as contrato_social, sum(case when idDocumentosFornecedoresTitulo = 2 then 1 else 0 end) as Ata_de_Negociação, sum(case when idDocumentosFornecedoresTitulo = 3 then 1 else 0 end) as Aceite_de_Condições_Gerais from dbo.tbFornecedores tbf left join tbDocumentosFornecedores df on tbf.idDocumentosFornecedore = df.idDocumentosFornecedore -- this is a guess group by tbf.idFornecedor, tbf.txtNomeResumido, tbf.txtNomeCompleto, tbf.bitHabilitado order by tbf.txtNomeResumido asc

{show: false}

Live Demo