【问题标题】:React : Pass param to render component with amplifyReact:将参数传递给使用放大的渲染组件
【发布时间】:2020-11-11 19:27:03
【问题描述】:

我对 React 还很陌生,并且遇到了问题。我有一个 index.tsx,它呈现 App 组件如下。

index.tsx

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';
import {initialize} from './util/initialize';

initialize().then(settings => {
    ReactDOM.render(<App settings={settings}/>, document.getElementById('root'));
});    

serviceWorker.unregister();

App.tsx

import React from "react";
import Search from "./search/Search";
import { withAuthenticator, AmplifySignOut } from '@aws-amplify/ui-react';

import "./App.css";

function App(settings : any) {
    return (
      <div className="App">
        <AmplifySignOut />
        <Search indexId={settings.ID!} region={settings.REGION!}/>
      </div>
    );
}

export default withAuthenticator(App);

我正在尝试将设置对象从 index.tsx 传递到 App 组件,但我不断收到错误

Type '{ settings: any; }' is not assignable to type 'IntrinsicAttributes & { children?: ReactNode; }'.

【问题讨论】:

    标签: reactjs react-native


    【解决方案1】:

    settings 被用作 index.tsx 文件中的道具。 App 将接受一个参数(通常称为props),它是一个包含所有道具的对象。试试这个,看看它是否对你有帮助:

    function App({settings}: {settings: any}) {

    【讨论】:

    • 不它dint..仍然同样的错误...在导出默认与Authenticator(App);
    • 这是完整的 TS 错误吗?如果没有,你能发布完整的错误吗?
    猜你喜欢
    • 2016-03-19
    • 2019-12-05
    • 2016-08-04
    • 2019-08-21
    • 2021-04-03
    • 1970-01-01
    • 1970-01-01
    • 2018-02-04
    • 2018-11-18
    相关资源
    最近更新 更多