draft-js icon indicating copy to clipboard operation
draft-js copied to clipboard

callback is not working for CompositeDecorator

Open vignestion opened this issue 7 years ago • 1 comments

I am trying to build an contentEditor with draft js Exactly the feature is Extract the data from url like Facebook.But I am stuck with this part .callback is not working...

First I wrapped my state with compositeDecorator Like this

 constructor(props){
                        super(props);
                        const compositeDecorator = new CompositeDecorator([
                           ....
                            {
                                strategy:linkStrategy,
                                component:decorateComponentWithProps(linkComp,{passit})
                            }
        ....
                
                        ]);
            
            }

This is my strategy


function linkStrategy(contentBlock, callback, contentState) {


        findLinkInText(LINK_REGEX,contentBlock,callback)
    }
function findLinkInText(regex, contentBlock, callback) {
    const text = contentBlock.getText();
    let matchArr, start;


    if((matchArr = regex.exec(text)) !== null){
        start = matchArr.index;
        let URL = matchArr[0];
        console.log(URL);


        axios.post('/url',{url:URL}).then(response => {
            passit = response.data

           //not working
            callback(start, start + URL.length)

        })

      //working
      callback(start, start + URL.length)





    }
}

If the callback won't works the component will not render .But the thing is I want to fetch the url data from my server And I have to pass the data via props to my component .And render it

vignestion avatar Apr 15 '17 17:04 vignestion

A solution for this is described here: https://github.com/facebook/draft-js/issues/2380

digitalgopnik avatar Feb 15 '22 08:02 digitalgopnik