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.

Cannot read property 'r' of null - React ES6 Project

See original GitHub issue

I currently have a JSON object that holds a number of color names and hex codes within my React project and am wanting to use nearest-color to show a user the nearest color to one they have entered in a HTML input field.


handleSearch(e) {
    let color = `#${e.target.value.replace("#", "")}`;

    if (color.length == 7) {

        let tempColors = this.state.colors;
        let colorsObj = {};

        // Iterates over state and creates a JSON Object with {color-name(key): color-hex(value)}
        for (let i = 0; i < tempColors.length; i++) {
            colorsObj[tempColors[i]] = Base[tempColors[i]]
        }

        var nearestColor = require('nearest-color').from(colorsObj);
        var newColor = nearestColor(color)
        console.log(newColor)
    }
}

My code compiles, however I receive this problem in Chrome when I enter a hex code such as #ffffff:

screen shot 2016-12-20 at 17 32 58

I’ve followed the README.md, so I’m not entirely sure where my code is falling over sadly.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
hesamdcommented, Oct 31, 2017

I had the same issue. I resolved it by adding # to my hex color codes.

1reaction
Zequezcommented, Apr 3, 2017

Might be the fact that if you don’t name your colors it doesn’t return an object with the {rgb} key, and then you’re trying to read {rgb: { r }}? That happened to me 😛

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: Cannot read property 'name' of null on export ...
TypeError : Cannot read property 'name' of null on export default function using react-scripts to compile ; Failed to compile. ./src/reducers/test ...
Read more >
Cannot Read Property of Undefined in JavaScript - Rollbar
TypeError : Cannot read property of undefined occurs when a property is read or a function is called on an undefined variable.
Read more >
Use ES6 Arrow Functions to Resolve "TypeError - Pluralsight
1TypeError : Cannot read property '<your property name>' of undefined. If you run into this error while writing React, the odds are high...
Read more >
Uncaught TypeError cannot read property 'addeventlistener' of ...
In JavaScript, a very common error is the Uncaught TypeError Cannot read property 'addeventlistener' of null. This error occurs when JavaScript is not...
Read more >
Cannot assign to read only property react - Caritas Castellaneta
The image does not copy and returns a JavaScript error: "Uncaught TypeError: Cannot assign to read only property". js in your project root...
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