Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

387
Views
draft js (react js) decoradores, después de 1000 palabras, el fondo del texto debe ser un cuadro de tweet de tweeter de color como

lo he hecho con decoradores, si no ingresé mientras escribía (creando un nuevo bloque), funciona bien, ingrese la descripción de la imagen aquí

pero cuando enviamos un mensaje de texto con el decorador de nueva línea, llama tantas veces como se creó una nueva línea y no funcionó, por favor, si alguien tiene una solución, por favor ayuda, gracias de antemano

ingrese la descripción de la imagen aquí

mi código de componente de reacción a continuación:

import React, { useState, useRef } from "react"; importar {Editor,
EditorState, ContentState, CompositeDecorator, convertToRaw, } from "draft-js";

const Decorado = ({hijos}) => { return {hijos}; };

function findWithRegex(contentBlock, callback) { const text = contentBlock.getText(); callback(1000, texto.longitud > 1000 ? texto.longitud : 1001); }

const estilos = { editor: { // borde: "1px gris sólido", // minHeight: "6em", }, };

función handleStrategy(contentBlock, devolución de llamada) {
findWithRegex(contentBlock, devolución de llamada); }

const createDecorator = () => new CompositeDecorator([ { estrategia: handleStrategy, componente: Decorado, }, ]);

function TextArea(props) { const [editorState, setEditorState] = useState( EditorState.createWithContent( ContentState.createFromText(props.value), createDecorator() ) );

const editor = useRef(null);

función focusEditor() { editor.current.focus(); }

const onChanage = (editState) => { const blocks = convertToRaw(editState.getCurrentContent()).blocks; let value = blocks .map((block) => (!block.text.trim() && "\n") || block.text) .join("\n"); setEditorState(editarEstado); props.formik.setFieldValue(props.name, value !== "\n" ? value : "") };

React.useEffect(() => { focusEditor(); }, []);

devolver ( ); }

exportar TextArea por defecto;

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!