Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

children与组合是否存在bug? #5046

Closed
ldwonday opened this issue Dec 10, 2019 · 7 comments
Closed

children与组合是否存在bug? #5046

ldwonday opened this issue Dec 10, 2019 · 7 comments
Assignees

Comments

@ldwonday
Copy link

ldwonday commented Dec 10, 2019

utils.ts

export const getYesterday = () => {
  return [
    moment(new Date())
      .add(-1, 'day')
      .startOf('day'),
    moment(new Date())
      .add(-1, 'day')
      .endOf('day'),
  ];
};

export const getDays = () => {
  return [
    moment(new Date())
      .add(-1, 'day')
      .startOf('day'),
    moment(new Date())
      .add(-1, 'day')
      .endOf('day'),
  ]
}

DataOverview.tsx:

import { getDays, getYesterday} from '../utils';
const yesterday = getYesterday();
const days = getDays()
const DataOverview: Taro.FC<ModelProps & DispatchProps> = props => {
  const [search, setSearch] = useState<ISearchParams>({
    dateRange: yesterday,
    allDays: days,
  });
  
  console.log(yesterday[0].format('l'), yesterday[1].format('l'), days[0].format('l'), days[1].format('l'))

  const searchHeaderProps = {
    onChange: (values: Partial<SearchHeaderParam>) => {
      const params = { ...search, ...values };
      setSearch(params);
    },
  };

  return (
    <View className="page-container">
      <SearchHeader {...searchHeaderProps} />
      <View className="container">
        <SortTable
          renderTitle={<SortTableTitle title="排行榜" range={search.dateRange} date={search.allDays}/>}
        />
      </View>
    </View>
  );
};

SearchHeader.tsx:

...
const handleSelectDateType = (type: EDateSelect) => {
    const range = [
      moment(new Date())
        .add(-7, 'day')
        .startOf('day'),
      moment(new Date())
        .add(-1, 'day')
        .endOf('day'),
    ];
    onChange({ dateRange: range, allDays: [
      moment(new Date())
        .add(-2, 'month')
        .startOf('day'),
      moment(new Date())
        .add(-1, 'day')
        .endOf('day'),
    ] });
  };
...

SortTableTitle.tsx:

interface SortTableTitleProps {
  title: string;
  range: moment.Moment[];
}

/** 无需使用range和date,只需定义即可复现 */
const SortTableTitle: Taro.FC<DataCardTitleProps> = ({ title, range, date  }) => {
  return (
    <View>
      {title}
      <Text className="cardTitleDesc"></Text>
    </View>
  );
};

export default SortTableTitle;

期望:

console.log(yesterday[0].format('l'), yesterday[1].format('l'), days[0].format('l'), days[1].format('l'))能输出预期的不变的常量结果。

结果:

yesterday,days会随着onChange变化而变化,当SortTableTitle组件去掉range和date,则console.log(yesterday[0].format('l'), yesterday[1].format('l'), days[0].format('l'), days[1].format('l'))输出为原本期望的结果。

备注:同样的代码react无此问题!

@taro-bot
Copy link

taro-bot bot commented Dec 10, 2019

CC @Chen-jj

@taro-bot
Copy link

taro-bot bot commented Dec 10, 2019

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~

@ldwonday ldwonday changed the title children与组合 children与组合是否存在bug? Dec 10, 2019
@ldwonday ldwonday reopened this Dec 10, 2019
@Chen-jj
Copy link
Contributor

Chen-jj commented Dec 11, 2019

@ldwonday 提供一下完整可复现代码

@ldwonday
Copy link
Author

@Chen-jj
Copy link
Contributor

Chen-jj commented Dec 12, 2019

#5012

@Chen-jj Chen-jj closed this as completed Dec 12, 2019
@ldwonday
Copy link
Author

@Chen-jj 关闭前可以给个解释吗?这是一个bug还是是我们自己写的不对?

@Chen-jj
Copy link
Contributor

Chen-jj commented Dec 12, 2019

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants