Home > database >  Writing react native with typescript with redux and react-redux
Writing react native with typescript with redux and react-redux

Time:10-01

I was wondering when I write redux action, reducers and store using typescript in React Native, should I give it an extension of .tsx or it can be .js only?

For instance this is my store.tsx file look like this:

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);

Should my files become all tsx extension in this case?

CodePudding user response:

If you are not using any Typescript code into that component than you don't need to make it .tsx but whenever you are using any Typescript functionality at that time you should, because typescript compiler accept .ts file and transpiled into JS,

And one suggestion if you have used .tsx everywhere in projects so i would suggest to use .tsx only to manage code structure properly.

So you can use accordingly

CodePudding user response:

Use .tsx or .ts if you don't have any JSX. Don't use .js or .jsx.

  • Related