我有一个与jQueryUI一起使用的按钮,就像这样(简化).
<button id="mybutton">Play<button>
<script>
$("#mybutton").button().toggle(
function(){
$(this).text('Stop');
},
function(){
$(this).text('Start');
},
);
</script>
Run Code Online (Sandbox Code Playgroud)
此代码打破了按钮的外观,因为当它进入按钮小部件时,按钮内部会添加一个新的跨度.所以我现在正在更改按钮值
$(this).find('span').text('Stop');
Run Code Online (Sandbox Code Playgroud)
这是hacky,因为我不能再把按钮当作黑盒子了,必须进去.
有干净的方法吗?
什么是cypher查询来查找属性不存在的节点?2个节点:A = {foo:true,名称:'A'},B = {name:'B'}
需要找到B,因为它没有foo,即B.foo未设置
我<Query>在一个组件中使用Apollo Client ,在生命周期方法中更改状态时重新呈现该组件.我希望我的<Query>组件重新运行查询,因为我知道数据已更改.在重新运行查询之前,Query组件似乎正在使用需要失效的缓存.
我正在使用一个不稳定的解决方法来缓存refetch来自父组件中的渲染道具的回调,但感觉不对.如果有人有兴趣,我会在答案中发布我的方法.
我的代码看起来像这样.为简洁起见,我从查询中删除loading并error处理了一些其他细节.
class ParentComponent extends React.Component {
componentDidUpdate(prevProps) {
if (this.props.refetchId !== prevProps.refetchId) {
const otherData = this.processData() // do something
this.setState({otherData}) // this forces component to reload
}
}
render() {
const { otherData } = this.state
return (
<Query query={MY_QUERY}>
{({ data }) => {
return <ChildComponent gqlData={data} stateData={otherData} />
}}
</Query>
)
}
}
Run Code Online (Sandbox Code Playgroud)
如何强制<Query>获取要传递的新数据<ChildComponent>?
即使ParentComponent在道具或状态发生变化时重新渲染,Query也不会重新运行. …
Stripe具有react-stripe-elements,提供injectStripeHOC。我们现在在2019年,而HOC不再酷了。Stripe似乎并不着急,我认为这是因为他们想支持React的较早版本,因此只关注最低的公分母解决方案。
我正在寻找一种stripe通过钩子获取的方法(而不是由提供的道具injectStripe)。
用法看起来像这样,
const stripe = useStripe()
以便以后可以使用stripe.handleCardSetup和其他API方法
import { CardElement } from 'react-stripe-elements'
const CardForm = ({secret}) => {
const stripe = useStripe()
const handleSubmit = async () => {
const { setupIntent, error } = await stripe.handleCardSetup(secret)
// ...
}
return (
<>
<CardElement />
<button onClick={handleSubmit} />
</>
)
}
Run Code Online (Sandbox Code Playgroud)
您如何定义useStripe现有API和组件的钩子?
stripe应该与您使用injectStripe钩子时得到的相同
GH上的相关问题:API评论:Hooks&Beyond
reactjs ×2
button ×1
cypher ×1
graphql ×1
jquery ×1
jquery-ui ×1
neo4j ×1
react-apollo ×1
react-hooks ×1