onFocus
我想知道 React events:和之间有什么区别onFocusCapture
。我在 React 的文档页面上找不到合适的答案。
<OutlinedInput
label="price from"
onFocus={handlePriceFocus}
/>
<OutlinedInput
label="price to"
onFocusCapture={handlePriceFocus}
/>
Run Code Online (Sandbox Code Playgroud)
就我而言,它似乎onFocus
具有onFocusCapture
相同的功能,因为我在使用这两个事件时没有注意到任何差异。
获取元素文本内容的方法有多种:getByText
vs findByText
vs queryByText
。
有时我对使用哪一个感到困惑。
我在反应本机中有以下示例:
it('should render children', () => {
const mockedChildComponentTxt = 'Children are rendered';
const { getByText, findByText, queryByText } = render(
<MyProvider>
<div>{mockedChildComponentTxt}</div>
</MyProvider>,
);
expect(queryByText(mockedChildComponentTxt)).toBeTruthy()
});
Run Code Online (Sandbox Code Playgroud)
queryByText
虽然getByText
失败了,但是findByText
有效。
debug()
导致:
<RNCSafeAreaView
onInsetsChange={[Function anonymous]}
style={
Object {
"flex": 1,
}
}
>
<div>
Children are rendered
</div>
</RNCSafeAreaView>
Run Code Online (Sandbox Code Playgroud)
为什么findByText
在上面的例子中可以工作,但是getByText
却queryByText
失败了?