我正在尝试使用自定义Material-UI Autocomplete组件并将其连接到react-hook-form.
TLDR:需要使用带有 react-hook-form 控制器的 MUI 自动完成而不需要
defaultValue
我的自定义Autocomplete组件采用具有结构的对象,{_id:'', name: ''}它显示名称并_id在选择选项时返回。该Autocomplete工作得很好。
<Autocomplete
options={options}
getOptionLabel={option => option.name}
getOptionSelected={(option, value) => option._id === value._id}
onChange={(event, newValue, reason) => {
handler(name, reason === 'clear' ? null : newValue._id);
}}
renderInput={params => <TextField {...params} {...inputProps} />}
/>
Run Code Online (Sandbox Code Playgroud)
为了使工作与react-hook-form我设置的setValues是处理程序onChange中Autocomplete,然后手动注册该组件在useEffect如下
useEffect(() => {
register({ name: "country1" });
},[]);
Run Code Online (Sandbox Code Playgroud)
这工作正常,但我想没有useEffect钩子,只是直接以某种方式使用寄存器。
接下来我尝试使用Controller组件 …
我已经在使用React Query库的项目上实现了无限滚动。
到目前为止,一切都很好。useInfiniteScroll使用钩子一切都按预期工作
我遇到的一个问题是这个库的缓存机制。如果我查询资源,例如: GET /posts/,将触发 GET /posts/?page=0,向下滚动一点,获取下一个结果, GET/posts/?page=1完全没问题。如果我将搜索参数添加到页面将执行 GET /posts/?filter=someValue&page=0。一切都很好...但是当我filter从搜索中删除它时,它会自动执行 GET /posts/?page=0& GET/posts/?page=1
remove()解决方案是使用查询本身的方法从缓存中删除查询。但这意味着我必须为每个查询手动执行此操作。
我希望获得一个涵盖所有情况的更好的解决方案。我有一个 queryWrapper 我想在其中处理这个问题。
我尝试使用 queryClient 实例invalidateQueries,resetQueries但似乎没有人能够将其从缓存中删除......
在下面的示例中,我保留了ref参数,如果它们发生更改,我可以触发查询以通过useLayoutEffect钩子重置。这部分按预期工作
无效查询尝试
queryClient.invalidateQueries(
[queryKey, JSON.stringify(paramsRef.current)],
{
exact: true,
refetchActive: false,
refetchInactive: false
},
{ cancelRefetch: true }
);
Run Code Online (Sandbox Code Playgroud)
重置查询尝试
queryClient
.resetQueries([queryKey, JSON.stringify(paramsRef.current)], {
refetchPage: (page, index) => index === 0
})
Run Code Online (Sandbox Code Playgroud)
我什至尝试了queryClient.clear()应该从缓存中删除所有现有查询的方法,但页码仍然以某种方式保留在缓存中...我使用useQueryClient钩子访问 queryClient。如果我检查它,我可以看到里面的查询。
有人可以帮我解决这个缓存问题吗?谢谢!
我正在尝试使用react-google-maps 库构建一个反应项目。
基本上它计算两点之间的最佳路线,并使用上面的库在地图上显示路线。
对于绘图,我使用Polyline和MarkerWithLabel模块:
我遇到的问题是标签的位置MarkerWithLabel,如果缩放级别设置为适合标签重叠的整个路线。这是因为标记非常接近并且缩放级别很小,这是正常的...
我还附上了2张图片
第二个缩放级别超过一个段(在我们的例子中是蒂米什瓦拉市)以实际查看所有标记

代码MarkerWithLabel如下
const Markers = () => segments.map((segment) => {
const { marker } = segment;
const style = styles.vehicles[marker.vehicle.kind];
return (
<MarkerWithLabel
key={marker.key}
position={{ lat: marker.lat, lng: marker.lng }}
labelAnchor={new goo.Point(-10, 15)}
noRedraw
icon={{
path: goo.SymbolPath.CIRCLE,
scale: 4,
strokeWeight: 2,
fillOpacity: 1,
fillColor: '#ff3f10',
strokeColor: '#ffffff',
}}
labelClass="marker-label"
labelStyle={{
width: '400px',
backgroundColor: 'none',
color: style.color,
}}
>
<div style={{ clearFix: 'both' …Run Code Online (Sandbox Code Playgroud) 我在 NodeJS 服务器中使用 Pug 和 Nodemailer 来处理电子邮件模板。
locals就我而言,对象中有以下对象
{
from: 'abc@xyz.com',
message: 'a\nb\nc\nd\ne',
}
Run Code Online (Sandbox Code Playgroud)
现在在 Pug 文件中我有以下行
p #{message}
Run Code Online (Sandbox Code Playgroud)
问题是在电子邮件中我没有收到带有新行的文本。
消息归档忽略\n并将所有内容放在同一行a b c d e
我需要使用对象中的新行获取页面中的文本。
a
b
c
d
e
Run Code Online (Sandbox Code Playgroud)
这个问题的解决方案是什么?
我对猫鼬的人口方法有疑问。遵循以下结构
const CompanySchema = new Schema({
name: String,
logo: String,
description: String,
address: String,
website: String,
phone: String,
email: String,
warehouses: [{ type: Schema.Types.ObjectId, ref: 'CompanyWarehouses' }],
});
const CompanyWarehouses = new Schema({
company: { type: Schema.Types.ObjectId, ref: 'Company' },
city: String,
});
Run Code Online (Sandbox Code Playgroud)
我在两个表中都有一些条目。我试图使用Populationfrom Mongoose来填充warehouses每个公司的字段。
使用以下查询
Company.find({}, 'warehouses -_id')
.populate({
path: 'warehouses',
})
.exec((err, docs) => {
console.log(docs);
});
Run Code Online (Sandbox Code Playgroud)
我得到以下结果
[ { warehouses: [ [Object], [Object], [Object] ] },
{ warehouses: [ [Object], [Object] ] …Run Code Online (Sandbox Code Playgroud)