React最佳实践中的高阶组件

时间:2018-06-03 20:42:17

标签: reactjs react-native higher-order-functions higher-order-components

所以我目前在React Native中有这种登录表单表示。 我喜欢更高阶组件的想法,但我想确保我正确地做到这一点。



style='page-break-after:always'




我的withEither()函数定义为



<div class='row small'>
        @foreach (var item in Model.BuyerList.ImageList)
        {
            <div style='page-break-after:always'>
                <div class="card bg-light mb-3 mr-1 card-text-fixed-width" >
                    <div class="img-control">
                        @if (!string.IsNullOrWhiteSpace(item.ImageUrl))
                        {
                            <img src="@item.ImageUrl" style="height:150px;" class="card-img-top" alt="Card image" />
                        }
                        else
                        {
                            <img src="~/AdTrack Images/NoProductImage.png" style="height:150px;" class="card-img-top" alt="Card image" />
                        }
                          <div class="edit d-print-none">
                                <a data-toggle="modal"
                                   data-id='{"id": "@item.Items.Number","ItemId":"@item.Items.ItemId", "AdId":"@item.Header.Id"}'
                                   class="open-AddBookDialog btn btn-primary" href="#"><i class="fa fa-pencil fa-lg"></i></a>
                            </div>

                            <div class="delete d-print-none">
                                <a data-toggle="modal" data-id='{"id": "@item.Items.Number","ItemId":"@item.Items.Id", "AdId":"@item.Id"}'
                                   class="open-delete btn btn-primary" href="#">
                                    <i class="fa fa-trash" style="font-size:15px;color:red" id="delete" name="delete"></i>
                                </a>
                            </div>

                            <div class="edit d-print-none">
                                <a data-toggle="modal"
                                   data-id='{"id": "@item.Items.Number","ItemId":"@item.Items.ItemId", "AdId":"@item.Header.Id"}'
                                   class="open-AddBookDialog btn btn-primary" href="#"><i class="fa fa-info-circle fa-lg"></i></a>
                            </div>
                        }
                    </div>
                    <div class="card-header">
                        <div class="font-weight-bold">Page @Html.DisplayFor(modelItem => item.Number)- @Html.DisplayFor(modelItem => item.Business)</div>
                        <div class="row mb-2 font-weight-bold">
                            <div class="col-md-6">Cut: @Html.DisplayFor(modelItem => item.Items.Number)</div>
                            <div class="col-md-6 text-right">9-Box: @Html.DisplayFor(modelItem => item.Items.BoxNumber)</div>
                        </div>
                        <div class="row mb-2 font-weight-bold">
                            <div class="col-md-4">Group @Html.DisplayFor(modelItem => item.Department.Test)</div>
                            @*<div class="col-md-4">Div: @Html.DisplayFor(modelItem => item.Department.Division)</div>*@
                            <div class="col-md-4">Buyer @Html.DisplayFor(modelItem => item.Department.Test)</div>
                            <div class="col-md-4">Dept @Html.DisplayFor(modelItem => item.Items.Department)</div>
                        </div>
                    </div>
                </div>
            </div>
        }
        </div>
&#13;
&#13;
&#13;

有一点让我感到惊讶的是,我在每个渲染刻度上组成并重建这些HOC。而不是仅仅静态地定义它们并传递道具。但是我不确定将props传递给条件组件的最佳方法。这样正确的道具就会被映射到正确的组件。

0 个答案:

没有答案