question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'.code' is undefined

See original GitHub issue

So, from time to time something breaks and my web app crashes cause of ".code' is undefined exception. I noticed that redux at this point is not even launching the "@@localize/INITIALIZE" but still adds languages and launches the "@@localize/ADD_TRANSLATION_FOR_LANGUAGE"

I tried to put the locale into localstorage to maybe perhaps avoid the undefined '.code' which occurs at "es/locale.js" => var activeLanguageCode = activeLanguage.code; and read the stored locale with store.subscribe but it did not helped at all, '.code' error is still happening.

I just followed the documentation, so I’m not sure what is going on This is how I’m dispatching it

store.dispatch(initialize([
    { name: 'English', code: 'en-US' },
    { name: 'German', code: 'de-DE' }
]))

store.dispatch(addTranslationForLanguage(settings.en_US, 'en-US'))
store.dispatch(addTranslationForLanguage(settings.de_DE, 'de-DE'))

akzqlhruticqsbq9couo6w 5_krby9qsfu2y6tj-yfaha m1dmpg7gr7sbpygyvjqitq

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ryandrewjohnsoncommented, Jan 20, 2018

Just to add to what @DarkSmile92 posted in case it helps someone else…

The dispatch prop can be called directly by store, but more often than not you will be calling dispatch from one of your components. It’s important to remember that as soon as you connect a component dispatch is added to it’s props directly. If you’re already using connect though you will more than likely want to add your action creators using mapDispatchToProps like so:

class App extends Component {

  componentWillMount() {
    /** 
     * NOTE: you don't need to call setActiveLanguage here...
     * 1. you shouldn't call it before initialize is called
     * 2. By default initialize will set the first language as your active language, you only need to 
          pass defaultLanguage if it's different than the first language in your languages array.
     */
    // dispatch(setActiveLanguage('en')); 
    
    // now the action creators are available in props, and have been wrapped with dispatch by connect
    this.props.initialize(languages); 
    this.props.addTranslationForLanguage(transEnUs, 'en');
    this.props.addTranslationForLanguage(transDe, 'de');
  }
}

// see mapDispatchToProps argument in react-redux https://github.com/reactjs/react-redux/blob/master/docs/api.md#arguments
const mapDispatchToProps = {
  initialize,
  addTranslationForLanguage
};

export default connect(null, mapDispatchToProps)(App);

@pardonmeme since I haven’t heard back from you I’m going to assume this issue is settled. If you find you’re still having issues feel free to comment.

0reactions
DarkSmile92commented, Jan 20, 2018

@ryandrewjohnson yes I solved mine. Hope this helps @pardonmeme with his.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is a 'undefined' in this code? - Stack Overflow
First you need to understand that variables declared with let have block scope. And you can not declare same variable again within same...
Read more >
undefined - JavaScript - MDN Web Docs - Mozilla
undefined is a property of the global object. That is, it is a variable in global scope. In all non-legacy browsers, undefined is...
Read more >
What does 'undefined' mean in programming terminology?
It means anything can happen. The compiler developer is free to do whatever he wants when a language standard does not specify what...
Read more >
What Is an Undefined Value? - Wise Geek
An undefined value typically occurs when there is an error in the code of a computer software program. Usually the variable that the...
Read more >
How to Check for Undefined in JavaScript | Coding at Dawn
In JavaScript programming, you will encounter the primitive data type undefined, which indicates the absence of a value.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found