小编Wil*_*ins的帖子

useEffect 依赖数组和 ESLint Exclusive-deps 规则

我有一个看起来像这样的组件:

const MyComponent = props => {
  const { checked, onChange, id } = props;
  const [isChecked, setChecked] = useState(false);

  useEffect(() => {
    onChange && onChange({ isChecked: !!checked, id });
    setChecked(checked);
  }, [checked]);

  const childProps = {
    id,
    isChecked
  };

  return <ChildComponent {...childProps} />;
};
Run Code Online (Sandbox Code Playgroud)

详尽的 deps lint 规则并不令人满意:

React Hook useEffect 缺少依赖项:idonChange. 包括它们或删除依赖项数组。(react-hooks/exhaustive-deps)eslint

我知道这一点id并且onChange不会改变,因此将它们添加到依赖项数组似乎没有必要。但规则不是警告,而是明确的指示去做某事。

是 ESLint 规则:

1)在这种情况下过于谨慎和有点愚蠢,所以可以忽略吗?

2) 突出最佳实践——即最大限度地减少将来可能发生的意外错误,例如,如果父组件的更改意味着 id在将来的某个时候更改?

3) 显示当前代码的实际/可能问题?

reactjs react-hooks use-effect

17
推荐指数
2
解决办法
2万
查看次数

用于区分ß和ss的SQL查询

似乎SQL中的ß= ss.我需要能够在严格的特征基础上进行区分.

即从表格中选择*,其中'%ß%'等名称会产生BrianBrußStevenSossmix

等等..

我查看了不同的Collat​​ions,看看是否有一个忽略了角色扩展,但到目前为止没有运气.

数据库默认使用Latin1_General_CI_AS - 我也尝试过Latin1_General_CS_AS和Latin1_General_CS_AS_WS,两者都没有用.

任何帮助,将不胜感激.

sql collation sql-server-2008

6
推荐指数
1
解决办法
3008
查看次数

Typescript 误解 - 为什么记录中需要所有属性?

在这个简单的例子中:

type AllowedKeys = 'a' | 'b'

const someObject: Record<AllowedKeys, boolean> = {a:true, b:false}

const anotherObject:  Record<AllowedKeys, boolean> = {a:true}
Run Code Online (Sandbox Code Playgroud)

someObject有效但anotherObject无效:

类型 '{ a: true; 中缺少属性 'b' 但在“Record<AllowedKeys, boolean>”类型中是必需的。

为什么是这样?

types typescript

6
推荐指数
1
解决办法
552
查看次数

任务异步控制器方法未命中

因此,我们有一个MVC项目,该项目已通过不同版本的MVC从1升级到4。

现在我们有一个控制器方法:

public async Task<ActionResult> IndexAsync()
Run Code Online (Sandbox Code Playgroud)

因此,如果我们转到http://somedomain.xyz/WhicheverController http://somedomain.xyz/WhicheverController/Index,则会收到404。

http://somedomain.xyz/WhicheverController/IndexAsync 路由到该方法就好了。

我们的路线出了什么问题?

c# asp.net-mvc routes asp.net-mvc-routing async-await

5
推荐指数
1
解决办法
3176
查看次数

嵌套div生成滚动条.为什么?

我有3个嵌套的div:

<div class="outer">
  <div class="inner"><div class="item"></div></div>
</div>
Run Code Online (Sandbox Code Playgroud)

.inner div是绝对位置,每个都有1px边框:

.outer{
  width:50%;
  height:100px;
  border: 1px solid red;
  position:relative;
  overflow-x:hidden;
  box-sizing:border-box;
}
.inner{
  border:1px solid blue;
  height:100%;
  position: absolute;
  box-sizing: border-box;
}
.item{
  width:100px;
  height:100%;
  background-color:yellow;
  display: inline-block;
  border:1px solid green;
  box-sizing:border-box;
}
Run Code Online (Sandbox Code Playgroud)

这种安排导致.outer div上的滚动条.

这是一个codepen

为什么这是我需要改变什么来阻止它发生?

如果.inner div的边框宽度增加到3px,则滚动条会消失.再次,为什么会发生这种情况?

html css border-box

5
推荐指数
1
解决办法
671
查看次数

使用 date-fns 设置日期格式

2021-09-20T12:12:36.166584+02:00我正在尝试使用库来格式化日期,date-fns但它不起作用,正确的方法是什么?

下面是我的代码:

import { format } from 'date-fns'
format(date, 'DD.MM.YYYY')
Run Code Online (Sandbox Code Playgroud)

javascript reactjs date-fns

4
推荐指数
1
解决办法
1万
查看次数

Typescript 在 Pick 实现中进行了扩展

这是本教程中TypescriptPick实用程序类型的基本实现

type ObjectWithKeys<T, K extends keyof T> = {
  [P in K]: T[P];
};
Run Code Online (Sandbox Code Playgroud)

我明白它的作用,但我发现它的用法K extends keyof T有点令人困惑。我们要确保 K 是联合类型 的成员(或成员的联合)keyof T。它永远不会“扩展”它,那么为什么extends在这里使用运算符呢?

Typescript 是否缺少运算符,而这是当前最好的选择?

types typescript

4
推荐指数
1
解决办法
1121
查看次数

将库添加到IOS应用程序会导致可怕的构建失败

我正在尝试将Apptentive添加到IOS应用程序中.已经有相当多的外部库被使用,例如Admob和Google分析.

我按照这个指南来写这封信,但我不能让它融合.看到下面讨厌的失败信息:

Undefined symbols for architecture armv7:
  "_kCTUnderlineStyleAttributeName", referenced from:
      -[ATTTTAttributedLabel commonInit] in libApptentiveConnect.a(TTTAttributedLabel.o)
  "_CTFontCopyName", referenced from:
      ___NSAttributedStringByScalingFontSize_block_invoke in libApptentiveConnect.a(TTTAttributedLabel.o)
  "_CTFontGetSize", referenced from:
      ___NSAttributedStringByScalingFontSize_block_invoke in libApptentiveConnect.a(TTTAttributedLabel.o)
  "_kCTForegroundColorFromContextAttributeName", referenced from:
      _NSAttributedStringBySettingColorFromContext in libApptentiveConnect.a(TTTAttributedLabel.o)
      ___NSAttributedStringBySettingColorFromContext_block_invoke in libApptentiveConnect.a(TTTAttributedLabel.o)
  "_CTFramesetterSuggestFrameSizeWithConstraints", referenced from:
      -[ATTTTAttributedLabel textRectForBounds:limitedToNumberOfLines:] in libApptentiveConnect.a(TTTAttributedLabel.o)
      -[ATTTTAttributedLabel sizeThatFits:] in libApptentiveConnect.a(TTTAttributedLabel.o)
  "_CTFontGetUnderlineThickness", referenced from:
      -[ATTTTAttributedLabel drawStrike:inRect:context:] in libApptentiveConnect.a(TTTAttributedLabel.o)
  "_CTLineGetGlyphRuns", referenced from:
      -[ATTTTAttributedLabel drawBackground:inRect:context:] in libApptentiveConnect.a(TTTAttributedLabel.o)
      -[ATTTTAttributedLabel drawStrike:inRect:context:] in libApptentiveConnect.a(TTTAttributedLabel.o)
  "_CTFrameGetLineOrigins", referenced from:
      -[ATTTTAttributedLabel characterIndexAtPoint:] in libApptentiveConnect.a(TTTAttributedLabel.o)
      -[ATTTTAttributedLabel drawFramesetter:attributedString:textRange:inRect:context:] in libApptentiveConnect.a(TTTAttributedLabel.o)
      -[ATTTTAttributedLabel drawBackground:inRect:context:] in …
Run Code Online (Sandbox Code Playgroud)

linker-errors ios apptentive

3
推荐指数
1
解决办法
2035
查看次数

当不满意时,SQL连接返回行

我有一张桌子Monkeys和一张桌子,上面Trees有一对多关系,由第三张MonkeysTreesFK表加入.

我有这个查询返回给定树的所有猴子和树Id:

SELECT * 
FROM Monkeys m
JOIN MonkeysTrees mt ON mt.MonkeyId = m.Id
join Trees t ON t.Id=mt.TreeId
WHERE t.Id = 1;
Run Code Online (Sandbox Code Playgroud)

如果我t.Id将final WHERE子句更改Id为不在Trees表中的那个,我仍然希望返回一个包含所有Monkeys的表,但在连接的字段中为NULL.我怎么能这样做?

sql-server null join

3
推荐指数
1
解决办法
52
查看次数

使用runSaga进行延误和延误测试

如果我有这样的传奇故事:

function * sagaWorker() {
  yield put(START_ACTION)
  yield take(WAIT_FOR_ACTION)
  yield delay(100)
  yield put(END_ACTION)
}
Run Code Online (Sandbox Code Playgroud)

我可以runSaga像这样成功地测试它:

step('saga passes the tests', async () => {
  const channel = stdChannel()
  const dispatched = []
  const options = {
    dispatch: action => dispatched.push(action),
    getState: () => {},
    channel
  }
  const task = runSaga(options, sagaWorker)
  channel.put(WAIT_FOR_ACTION)
  await task.toPromise()
  expect(dispatched).to.deep.eql([START_ACTION, END_ACTION])
})
Run Code Online (Sandbox Code Playgroud)

但是,如果我将延迟转移到汇票的前面:

function * sagaWorker() {
  yield put(START_ACTION)
  yield delay(100)
  yield take(WAIT_FOR_ACTION)
  yield put(END_ACTION)
}
Run Code Online (Sandbox Code Playgroud)

现在,传奇故事没有完成并超时-到达了,take但动作从未到达频道。

是否可以使用此表格进行测试?我怀疑我可以使它通过工作call荷兰国际集团的delay真是让人不是 …

javascript redux redux-saga

3
推荐指数
1
解决办法
235
查看次数

单元测试 redux-saga select

我有一个这种形式的简单传奇:

const getAccountDetails = function * () {
   const { url } = yield select(state => state.appConfig)
   const accountDetails = yield call(apiFetchAccountDetails, url)
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试编写单元测试:

describe('getAccountDetails', () => {
    const iterator = getAccountDetails()
    it("should yield an Effect 'select(state=> state.appConfig)'", () => {
       const effect = iterator.next().value
       const expected = select(state => state.appConfig)
       expect(effect).to.deep.eql(expected)
    })
Run Code Online (Sandbox Code Playgroud)

此测试失败。尽管effectexpected非常相似,但它们并不完全相同。

至少有一个差异被隐藏在 中payload.selector.scopes,其中产生的效果和预期如下:

截屏

由于这两者的范围总是不同的,如何才能使这些测试起作用?

eta:此模式改编自redux-saga 文档中链接的示例

generator mocha.js chai redux-saga

2
推荐指数
1
解决办法
2111
查看次数

向 UITabBarController 添加滑动面板

我制作了一个带有可以从屏幕底部向上拖动的选项卡的面板。

我想将它添加到 UITabBarController 中,以便它出现在所有 tabBar 子视图中,但它必须看起来从标签栏本身的顶部滑出。我可以将面板添加到与 UITabBarController 相同的顶级视图,但它会滑过选项卡栏的顶部。

在 UITabBarController 中是否有一个子视图,可以在其中添加此滑块,使其按需要运行,而无需以编程方式裁剪面板视图的底部?

uitabbarcontroller ios

1
推荐指数
1
解决办法
687
查看次数

Interface Builder IBOutlet - 没有@synthesize

我正在使用XCode 4.4.1来学习iPhone开发.

我正在我的ABCViewController.h标题中创建出口属性,方法是从UIObject的弹出菜单中的"引用出口"部分拖动.这增加了如下行:

@property (strong, nonatomic) IBOutlet UITextField *nameField;
Run Code Online (Sandbox Code Playgroud)

到头文件.

现在,当我查看相应的ABCViewController.m文件时,我期待看到

@synthesize nameField; 
Run Code Online (Sandbox Code Playgroud)

在某处自动生成.但事实并非如此 - 我必须手动添加每个@synthesize语句.

这只是一个小小的问题,但我想知道出了什么问题.

有任何想法吗?

iboutlet ios xcode4

0
推荐指数
1
解决办法
537
查看次数