简体   繁体   English

ReactiveSearch 自定义组件和清除过滤器

[英]ReactiveSearch custom component and clear filters

I created a custom ReactiveComponent based on the official docs: https://docs.appbase.io/docs/reactivesearch/v3/advanced/reactivecomponent/我根据官方文档创建了一个自定义 ReactiveComponent: https://docs.appbase.io/docs/reactivesearch/v3/advanced/reactivecomponent/

This works fine, however when I use the component and clear the filter of my custom component, how can I update the ui state of the custom component?这工作正常,但是当我使用组件并清除自定义组件的过滤器时,如何更新自定义组件的 ui state?

Using the example in the docs: When clearing the color filter, how can I update the ColorPicker UI state to reflect that no color is selected?使用文档中的示例:清除颜色过滤器时,如何更新 ColorPicker UI state 以反映未选择颜色?

Haven't found anything related to this in the docs.在文档中没有找到与此相关的任何内容。

In case anyone else encounters the same issue: The render props of include a value object which is set to null if you clear the filters.万一其他人遇到同样的问题:如果清除过滤器,则渲染道具包括值 object 设置为 null。 This way it is possible to conditionally update the ColorPicker UI state (or whatever custom component you use).通过这种方式,可以有条件地更新 ColorPicker UI state(或您使用的任何自定义组件)。

If I understand clear you need to use value that coming via render prop.如果我明白你需要使用通过渲染道具来的价值。

Here is an example usage from my project这是我项目中的一个示例用法

 render={({ data, handleChange, value }) => {
                return (
                  <div
                    role="listbox"
                    aria-label="SpecialCategoryFilter-items"
                    className="list-filter"
                  >
                    {data.map((item) => (
                      <p
                        className="button-large-item"
                        key={item.key}
                        role="option"
                        aria-checked={value[item.key] ? true : false}
                        aria-selected={value[item.key] ? true : false}
                      >
                        <input
                          style={{ display: "none" }}
                          type="checkbox"
                          value={item.key}
                          onChange={(e) => {
                            handleChange(e);
                          }}
                          id={"SpecialCategoryFilter-" + item.key}
                          name={"SpecialCategoryFilter-" + item.key}
                        />
                        <label
                          htmlFor={"SpecialCategoryFilter-" + item.key}
                        >
                          <span>{item.key}</span>
                        </label>
                      </p>
                    ))}
                  </div>
                );
              }}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM