我现在正在做一些React,我想知道是否有一种"正确"的方式来做条件样式.在他们使用的教程中
style={{
textDecoration: completed ? 'line-through' : 'none'
}}
Run Code Online (Sandbox Code Playgroud)
我不想使用内联样式,所以我想改为使用类来控制条件样式.如何以React的思维方式解决这个问题?或者我应该使用这种内联样式方式?
我已经用这样的打字稿设置了一个 redux thunk 函数:
export const fetchActivities = (): AppThunk => async dispatch => {
dispatch(fetchActivitiesRequest())
try {
const res = await fetch("/activities")
const body = await res.json()
dispatch(fetchActivitiesSuccess(body))
} catch (err) {
dispatch(fetchActivitiesError(err))
}
}
Run Code Online (Sandbox Code Playgroud)
AppThunk 只是从 ThunkAction 类型派生的类型,具有以下类型参数:
export type AppThunk<ReturnType = void> = ThunkAction<ReturnType, {}, null, Action<string>>
Run Code Online (Sandbox Code Playgroud)
我的问题是,当我尝试为我的操作设置单元测试时,以及当我尝试像这样分派 thunk 操作时:
const middlewares = [thunk]
const mockStore = configureMockStore(middlewares)
const store = mockStore({ activities: [] })
store.dispatch(actions.fetchActivities())
Run Code Online (Sandbox Code Playgroud)
我收到以下错误消息:
Argument of type 'ThunkAction<void, {}, null, Action<string>>' is not assignable …
Run Code Online (Sandbox Code Playgroud) 我有一个基于ReactJS的博客实现,我想与AddThis集成.我有我的社交图标,我想使用它们.所以我正在寻找一种只集成AddThis后端服务的方法.
我试着环顾四周,但我无法找到如何将AddThis集成到ReactJS组件.
我在某个地方看到了它,并且它使用了一个特殊的命名空间,据我所知,这个命名空间并不友好.
<div addthis:url='blog_url' addthis:title='blog_title' class="addthis_toolbox">
<a class="addthis_button_facebook">
<svg ... />
</a>
<a class="addthis_button_twitter">
<svg ... />
</a>
<a class="addthis_button_linkedin">
<svg ... />
</a>
<a class="addthis_button_reddit">
<svg ... />
</a>
</div>
<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=xa-4fc9383e1ee05f1b"></script>
Run Code Online (Sandbox Code Playgroud)
另外,我看到这个JSFiddle有一些信息,但它没有使用ReactJS,也没有使用自定义图标.
问题:AddThis + React有没有好的文档?