为什么在传递道具时需要使用传播算子

时间:2019-04-09 14:07:20

标签: javascript reactjs

下面是代码:

CookieManager manager = new CookieManager();
           CookieHandler.setDefault(manager);

           OkHttpClient.Builder client = new OkHttpClient().newBuilder().cookieJar(new JavaNetCookieJar(manager));

            RequestBody reqbody = RequestBody.create(null, new byte[0]);
            Request request = new Request
                   .Builder()
                   .url(Utility.getRestaurationUrl(context).concat("/login/jwt/"))
                    .method("POST",reqbody)
                   .addHeader("Authorization",token)
                   .build();
            try {
                Response response = client.build().newCall(request).execute();
                List<HttpCookie> cook = manager.getCookieStore().getCookies();
            } catch (IOException e) {
                e.printStackTrace();
            }

我不明白的是,为什么必须这样:

const Info = (props) => (
    <div>
        <h1>Info</h1>
        <p>The info is: {props.info}</p>
    </div>
);

const withAdminWarning = (WrappedComponent) => {
    return (props) => (
        <div>
           <p>This is private info. Please don't share!</p>
           <WrappedComponent {...props}/>   // why need to use spread operator?
        </div>
    );
};

const AdminInfo = withAdminWarning(Info);

ReactDOM.render(<AdminInfo info="There are the details" />, document.getElementById('app'));

而且我不能将对象传递为:

 <WrappedComponent {...props}/>  

不是{... props}个对象吗?

1 个答案:

答案 0 :(得分:-1)

您不需要使用传播运算符,也可以执行类似的操作

const temp = { info: "There are the details }
<WrappedElement temp={temp} />

您以后可以使用props.temp.info

进行访问
相关问题