JavaScript Error Null Is Not an Object

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



Leave a reply



Submit