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.

TypeError: Cannot read property 'brandPrimary' of undefined

See original GitHub issue

react-native, react and native-base version

"react": "16.2.0",
"react-native": "0.53.0",
"native-base": "^2.3.7",

Expected behaviour

The Jest test suite is expected to run & tests pass

Actual behaviour

    TypeError: Cannot read property 'brandPrimary' of undefined
      
      at Object.<anonymous> (node_modules/native-base/src/theme/variables/platform.js:196:20)
      at Object.<anonymous> (node_modules/native-base/dist/src/theme/components/Body.js:1:112)
      at Object.<anonymous> (node_modules/native-base/src/theme/components/index.js:2:1)

Steps to reproduce (code snippet or screenshot)

  1. Create a simple component like:
import React, { Component } from 'react';
import { Footer, Text, Left, Body, Right } from 'native-base';

class SimpleComponent extends Component {
  render() {
    const { leftText, rightText } = this.props;
    return (
      <Footer>
        <Left>
          <Text>{leftText}</Text>
        </Left>
        <Body/>
        <Right>
          <Text>{rightText}</Text>
        </Right>
      </Footer>
    );
  }
}

export default SimpleComponent;

  1. Add a simple test:
describe('Components | SimpleComponent', function () {
  let wrapper;
  const leftTest = 'Text';
  beforeEach(() => {
    wrapper = shallow(<SimpleComponent leftTest={leftTest}/>);
  });

  it('renders leftText', function () {
    expect(wrapper.find(Text).text()).to.eq(leftTest);
  });
});

  1. yarn test / npm test

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
thomaswinckellcommented, Feb 12, 2018

To solve this issue, just replace this :

radioColor: this.brandPrimary,

by this :

get radioColor() {
    return this.brandPrimary;
},

in files native-base-theme/variables/platform.js and native-base-theme/variables/material.js at line 196.

This is due to the fact that you cannot access an object property while declaring it. So, in my solution, i am using a computed property, which will be evaluated at runtime.

I can do a PR if you want.

2reactions
SupriyaKalghatgicommented, Mar 5, 2018

@panuhorsmalahti In a day or two

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: Cannot read property displayQuestion of undefined
Here is my code below, all I am trying to do is have it select one of the random questions, prompt the user...
Read more >
[highcharts-more] Cannot read properties of undefined ...
Any ideas? Code: Select all TypeError: Cannot read properties of undefined (reading 'forEach') at t.<anonymous> (/_next/ ...
Read more >
ERROR TypeError: Cannot read property title of undefined
HEY, SET YOUR LIKE THERE ! ... Your browser can't play this video. ... Solved: ERROR TypeError : Cannot read property title of...
Read more >
Cannot read properties of undefined' - JavaScript Debugging
JavaScript Tutorial. How To Fix 'Uncaught TypeError : Cannot read properties of undefined ' - JavaScript Debugging. 25K views 6 months ago.
Read more >
Restyle for React Native (vs Styled System) - Ryosuke
It displayed an error Uncaught TypeError: Cannot read property 'defaults' of undefined which didn't help. I tried adding the example text ...
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