Cannot read property 'r' of null - React ES6 Project
See original GitHub issueI 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
:
I’ve followed the README.md, so I’m not entirely sure where my code is falling over sadly.
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I had the same issue. I resolved it by adding
#
to my hex color codes.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 😛