Skip to content
This repository has been archived by the owner on Aug 1, 2022. It is now read-only.

"Cannot read property loadSaveData of null " OR"Cannot read property 'current' of undefined " #106

Closed
priyanka-zotalabs opened this issue Dec 21, 2020 · 1 comment
Labels
bug Something isn't working question Further information is requested

Comments

@priyanka-zotalabs
Copy link

Code :-

import React, { useState, useEffect,useRef, } from "react";
import {Modal,Row,Col,Form,} from "react-bootstrap";

import {Paper, makeStyles,Button,} from "@material-ui/core";
import CanvasDraw from "react-canvas-draw";

const Homework = (props) => {

const valueRef2 = useRef(
Array.from({ length: 50 }, () => React.createRef())
);

console.log("show doodle", valueRef2, valueRef2.current);

// getting required data in homework from previouse component
const [homeworkDatasss1, setHomeworkDatasss1] = useState(homework);

useEffect(() => {
if (homeworkDatasss1) {
homeworkDatasss1.forEach((element) => {
console.log("element", element);
if (element.status == "checked") {
element.submittedHomework.submittedHomeworkUrls.forEach((test2) => {
console.log("student data", test2);

// getting all data of test2.index & test2.doodle
console.log("doodle data",test2.index,test2.doodle)

          valueRef2.current[test2.index].current.loadSaveData(test2.doodle);
        });
      }
    });

// some code to update other states
}
}, [homeworkDatasss1]);

return (
<React.Fragment>
{homeworkDatasss1 ? (
{homeworkDatasss1.length > 0 &&
homeworkDatasss1.map((course, j) => (


{course.submittedHomework.submittedHomeworkUrls.map((test, j) => (

{
valueRef2.current[j]!== undefined &&
valueRef2.current[j]!== null &&
valueRef2.current[j]?
(

<CanvasDraw

imgSrc={test.url.toString()}
hideGrid={true}
brushColor="red"
brushRadius={2}
disabled
style={{ border: "1px solid black" }}
ref={valueRef2.current[test.index]}
canvasWidth={600}
canvasHeight={600}
/>

):( null ) }
))}         
                </Col>

              </Row>
); };

export default Homework;

2020-12-21 (2)

In this code test2.doodle is string of canvas data getting saved in other component
"const data = firstCanvas.current[Index].current.getSaveData()" .I want to dedocode this string to show doodle on images
using array ref , want to save in such a way -> valueRef2.current[test2.index].current.loadSaveData(test2.doodle);

but getting errors like "Cannot read property loadSaveData of null " OR"Cannot read property 'current' of undefined "

Is anything i am doing wrong Or Other way to do it /solve it .

@priyanka-zotalabs
Copy link
Author

@embiem embiem added bug Something isn't working question Further information is requested labels Nov 7, 2021
@embiem embiem mentioned this issue Nov 7, 2021
2 tasks
@embiem embiem closed this as completed Nov 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants