Reputation: 147
I am trying to learn redux and I have a file with an action in it.
export const changeTitle = () => {
return {
type: 'CHANGE_PROJECT_TITLE',
};
};
Then I am trying to import it in a component.
import changeTitle from '../actions/index.js';
This works if I use export default in the action file but then I can only have one action.
export default changeTitle;
I am trying to figure out why it will not work without the the export default. When I try without the export default I get an error that says : "Attempted import error: '../actions/index.js' does not contain a default export (imported as 'changeTitle')." I believe I have seen examples that work without the default export so they can use multiple actions.
Upvotes: 0
Views: 941
Reputation: 36
in your case just change
import changeTitle from '../actions/index.js';
to
import { changeTitle } from '../actions/index.js';
and you can omit index.js name in import, it's default file for import
import { changeTitle } from '../actions';
more information about export you can find on mdn
Upvotes: 2