Error trying to export a constant in React

Asked

Viewed 144 times

0

I have created this:

const funcionarioReducer = (state = [], action) => {
    switch(action.type) {
      case 'ADD_FUNCIONARIO':
        return state.concat([action.data]);
      default:
        return state;
    }
}
export default funcionarioReducer;

I try to import it in index.js to create a store:

import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import { createStore } from 'redux';
import { Provider } from 'react-redux';

import { funcionarioReducer } from './reducers/funcionarioReducer';
const store = createStore(funcionarioReducer);


ReactDOM.render(
    <Provider store={store}>
    <App />
    </Provider>, document.getElementById('root')
)

But when I run the project I get:

Attempted import error: 'funcioReducer' is not Exported from '. /reducers/functionReducer'.

I’m studying as a base this tutorial, from what I realize I’m doing exactly the same as what it specifies, but I keep getting this error.

1 answer

0

Strange this mistake you get.

Anyway, I believe the solution is to realize a default import instead of a named import, since you make a export default. To do this, simply import the funcionarioReducer as follows:

import funcionarioReducer from './reducers/funcionarioReducer';

I created a Codesandbox with a structure similar to the one you presented and worked with the amendment I quoted.

To learn more about default import and named import, recommend the following reading.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.