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

178
Views
DraftJS maneja el enfoque cuando la página tiene un editor múltiple (editable y de solo lectura)

Estoy enfrentando un problema con el componente del editor de seguimiento de DraftJS.

 import React, { useRef } from "react"; import styled from "styled-components"; import { EditorState, Editor as DraftEdior } from "draft-js"; const Wrapper = styled.div` border: 1px solid #ccc; padding: 1rem; `; interface IEditorProps { state: EditorState; onChange: (state: EditorState) => void; readOnly?: boolean; } export const Editor: React.FunctionComponent<IEditorProps> = (props) => { const { state, onChange, readOnly } = props; const ref = useRef<DraftEdior | null>(null); return ( <Wrapper onClick={() => ref?.current?.focus()}> <DraftEdior ref={ref} editorState={state} onChange={onChange} readOnly={!!readOnly} /> </Wrapper> ); }; export default Editor;

y la aplicación.js

 import React from "react"; import { EditorState } from "draft-js"; import { Editor } from "./Editor"; const App = () => { const [state, setState] = React.useState<EditorState>(() => EditorState.createEmpty() ); return ( <> <h3>Editor</h3> <Editor state={state} onChange={(state) => setState(state)} /> <h3>Result</h3> <Editor state={state} readOnly onChange={() => null} /> </> ); }; export default App;

Cuando solo hay un editor en la página, todo funciona bien. Pero el editor perdía continuamente el foco cuando añadía un componente de solo lectura.

Este es un enlace de código sanbox

https://codesandbox.io/s/vigilant-wilson-70op8?file=/src/App.tsx:0-451

Como solucionarlo, muchas gracias.

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!