我有以下代码:
const initialState = {
searchItems: ['Item'],
}
export default (state = initialState, action) => {
switch (action.type) {
case BACKSPACE_REMOVE_SEARCH_ITEM:
console.log(state.searchItems);
return {
...state,
searchItems: [...state.searchItems.splice(-1)],
};
default:
return state;
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试执行这样的操作时,我收到了与之前相同的数组,里面有 'Item',它不会'删除它。哪里有问题?
我在页面上有 div,我需要知道它与视口相关的右侧的位置。我试过这段代码:
const el = this.searchWrapper.getBoundingClientRect();
el.right
Run Code Online (Sandbox Code Playgroud)
但这不是我需要的,因为 getBoundingClientRect() 从左侧开始计算,但我需要计算元素和视口右侧之间的距离,如下面的屏幕所示

如果将数据正确地推送到firebase或者如果被拒绝则捕获错误,我希望获得成功.我试过这样的代码:
db.push().set(todo).then(snap => {
console.log(snap);
});
Run Code Online (Sandbox Code Playgroud)
但SNAP,回调,是不明确的.我如何在这里使用承诺?
当用户在输入字段中键入一些信息时,我在执行对服务器的请求时遇到问题。已发送请求,但如果用户快速从字段中删除所有内容,则不会默认发送请求,但会发送最后一个字母。因此会发生一些延迟。
我需要意识到当用户快速键入内容并以2ms的速度发送一次请求时,会发生某种方式的反跳
<input type="text"
placeholder="add"
className='input'
onChange={(e) => this.search(e.target.value)}
onKeyDown={this.handleSearchParam}
value={keyword}
/>
Run Code Online (Sandbox Code Playgroud)
处理输入的功能
search(text) {
this.props.onTextInputAdd(text);
if (text) {
this.props.onSearchTypeResult(this.props.tab, text)
} else {
this.props.onLoadDefaultInfo(this.props.tab);
}
}
const mapStateToProps = state => ({
keyword: state.searchReducers.keyword,
});
const mapDispatchToProps = dispatch => ({
onSearchTypeResult: (tabName, query) => dispatch(actionCreators.loadSearchInfo(tab, tabQuery)),
onTextInputAdd: keyword => dispatch(actionCreators.addKeyword(keyword)),
});
Run Code Online (Sandbox Code Playgroud)
这是动作:
const loadSearchResults = (tabName, query) => axios.get(`testurl?query1=${tabName}&query2=${query}`)
export const loadSearchInfo = (tabName, query) => dispatch => {
loadSearchResults(tabName, query).then(response => {
const data = { ...response.data …Run Code Online (Sandbox Code Playgroud) 我无法理解如何正确渲染元素中的测试。我写了这样一个测试:
const props = {
type: 'test_plan',
renewal: '25.06.2019',
subscriptionName: 'Test',
};
test('test component elements render', () => {
const wrapper = mount(<Component {...props} />);
console.log(wrapper.debug())
expect(wrapper.find('.link')).to.have.lengthOf(0);
expect(wrapper.find('type')).to.have.lengthOf(1);
});
Run Code Online (Sandbox Code Playgroud)
这是调试组件时我在控制台中的内容:
<div className="wrapper">
<div className="mobile">
<h3>
Test
</h3>
</div>
<div className="inner">
<h3>
Test
</h3>
<div className="type">
<h4>
Test Type 1
</h4>
<span>
25.06.2019
</span>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
这是我的错误 Cannot read property 'have' of undefined
如何正确测试组件中的元素是否呈现?
我有这样的生命周期钩子
componentDidUpdate(prevProps) {
// Typical usage (don't forget to compare props):
if (prevProps.activeItems !== this.props.activeItems) {
this.props.doAction();
}
}
Run Code Online (Sandbox Code Playgroud)
和道具有这样的结构
[
{id:1, hidden: true},
{id:2, hidden: false}
{id:3, hidden: true}
]
Run Code Online (Sandbox Code Playgroud)
我需要检查每个对象的 prev 和 next props 中的属性 hidden 是否相同,因此我将知道是否需要在 if 条件下运行函数。我怎样才能做到这一点?