reactjs - 使用带有 redux 和 react-redux 的 typescript 编写 react native
问题描述
我想知道当我在 React Native 中使用 typescript 编写 redux action、reducers 和 store 时,我应该给它一个扩展.tsx
还是.js
只能?
例如,这是我的store.tsx
文件如下所示:
import {createStore, applyMiddleware, combineReducers} from 'redux';
import {composeWithDevTools} from 'redux-devtools-extension';
import thunk from 'redux-thunk';
import newsReducer from './reducers/newsReducer';
const rootReducer = combineReducers({
news: newsReducer,
});
const middleware = composeWithDevTools(applyMiddleware(thunk));
export default createStore(rootReducer, middleware);
在这种情况下,我的文件是否应该成为所有tsx
扩展名?
解决方案
如果您没有在该组件中使用任何 Typescript 代码,则不需要将其设为 .tsx,但无论何时使用任何 Typescript 功能,您都应该这样做,因为 typescript 编译器接受 .ts 文件并转译为 JS,
如果您在项目中的任何地方都使用过 .tsx ,那么我建议您仅使用 .tsx 来正确管理代码结构。
所以你可以相应地使用
推荐阅读
- android - Fabric crashlytics 到 Firebase 迁移
- javascript - 使用 react 访问移动网络摄像机
- python - 图像重建(侵蚀和膨胀)都将黑色图像作为输出
- laravel - 防止 axios 在组件外部获取请求
- php - 我想要一个易于理解的代码来根据今天的日期从表中选择一组行
- python - 如何通过命令行将多个列表参数传递给多个 pytest 夹具
- javascript - 如何获取div中的图像来源反应原生
- html - Angular 9:无法实例化循环依赖
- python - AttributeError:“namespace#”对象的属性“FileStream”是只读的
- spring-boot - 当我在春季启动 cosmosDb 中执行 repository.save 时,Mono 值是 MonoOnErrorResume