Javascript Error Null is not an Object
Put the code so it executes after the elements are defined, either with a DOM ready callback or place the source under the elements in the HTML.
document.getElementById()
returns null
if the element couldn't be found. Property assignment can only occur on objects. null
is not an object (contrary to what typeof
says).
TypeError: null is not an object (evaluating 'arr.push')
The problem is that your variable is null .. but it expects a list.
Try this:
addTodo = () => {
var newTodo = this.state.text;
var arr = this.state.todo !== null ? this.state.todo : [];
if (!newTodo) {
alert("Empty!");
} else {
arr.push(newTodo);
this.setState({ todo: arr, text: "" });
this.setDataLocally();
}
How do I resolve 'Null is not an object' error when evaluating RNRandomBytes.seed
I had the same problem and after some research, this is what did work for me:
1- Adding buffer and events
Error: Unable to resolve module `buffer` React Native
2- Seed problem: switch from react-native-randombytes to react-native-get-random-values
TypeError: null is not an object (evaluating 'RNRandomBytes.seed') React Native
3- Fix stream problem in cipher-base with readable-stream by adding 'patch-package'
https://github.com/crypto-browserify/cipher-base/issues/10
And finally this is how I implemented the solution in a custom hook to get my random words :
import { useState, useEffect } from "react";
import "react-native-get-random-values";
import { entropyToMnemonic } from "bip39";
export default function UseBip39() {
const [state, setState] = useState([]);
useEffect(() => {
async function generateWords() {
const entropy = await crypto.getRandomValues(new Uint8Array(16));
setState(entropyToMnemonic(entropy).split(" "));
}
generateWords();
}, []);
return state;
}
Related Topics
Invert Text Color on Mouse Hover
How to Get a Number Value from an Input Field
Delay Removing a Class in Jquery
Resize Cross Domain Iframe Height
Why Are CSS Animations and Transitions Blocked by JavaScript
What Blocks Ruby, Python to Get JavaScript V8 Speed
How to Get JavaScript Caller Function Line Number and Caller Source Url
Create an Array with Same Element Repeated Multiple Times
What Is the Promise Disposer Pattern
How to Break Line in JavaScript
How to Add "Href" Attribute to a Link Dynamically Using JavaScript
Es6 Module Import Giving "Uncaught Syntaxerror: Unexpected Identifier"
How to Get a Floating Footer to Stick to the Bottom of the Viewport in Ie 6
Detecting by How Much User Has Scrolled
Why Browser Is Returning Empty String on Style.Height ? How to Get Actual Height of an Element
How to Raw Url Encode/Decode in JavaScript and Ruby to Get the Same Values in Both