Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

35
Views
add array of strings into object using 2 functions

I'm creating a NoteEditor, using react. I have 2 textarea in my popup, and when i'm trying to add my array of strings into object, i have a mistake, that my variable, which is contains this arrayOfStrings returns 'undefined', when i'm clicking the button add note.

There is my function onDescriptionChange, i take the e.target.value from my textarea and add to variable arrayOfStrings, where split this string into array with words:

let onDescriptionChange = (e) => {
    setTextAreaHeight(e, '100px');
    let stringToSplit = e.target.value;
    let arrayOfStrings = stringToSplit.split(' ');
    return arrayOfStrings;
};

There is a function addArrayToNote, where I'm trying to add this arrayOfStrings into description:

let addArrayToNote = (arrayOfStrings) => {
    setNote({
        ...note,
        description: arrayOfStrings,
    });
    addNote();
};

I will be very grateful if you help...

7 months ago · Juan Pablo Isaza
1 answers
Answer question

0

I believe you want to invoke the method addArrayToNote after generating the arrayOfStrings.

let onDescriptionChange = (e) => {
    setTextAreaHeight(e, '100px');
    let stringToSplit = e.target.value;
    let arrayOfStrings = stringToSplit.split(' ');
    // return arrayOfStrings; instead of returning the value
    addArrayToNote(arrayOfStrings) // invoke the addArrayToNote with the strings.

};
let addArrayToNote = (arrayOfStrings) => {
    setNote({
        ...note,
        description: arrayOfStrings,
    });
    addNote();
};

I hope this helps.

7 months ago · Juan Pablo Isaza Report
Answer question
Find remote jobs