0

I have some react Code

  onFinish = value => {
    fetch(`filter?layout=false&q[city_id_eq]=${this.state.value}`, {
      method: 'GET'
    })
      .then(response => response.text())
      .then(content => document.getElementById('filter-content').innerHTML = content)    
  };

It works, BUT the problem is this line:

.then(content => document.getElementById('filter-content').innerHTML = content)   

no scripts can be inserted with .innerHTML or there are ways around, which seem to be super complicated, like here Can scripts be inserted with innerHTML?

I am new to React and I am looking for a way to load HTML including the script I have (which is a map, having around 50 lines of code. More complicated, it's map written in a ruby file... ) Please help, none of the suggested options in the link above helped so far. I kind of need to look for script-Tags in my #filter-content and load them into the Page content.

Katharina Schreiber
  • 1,187
  • 2
  • 11
  • 38
  • 1
    The solutions aren't entirely trivial, but they're not hard to implement either - just copy-paste mmm's code into yours, then call it on the `#filter-content` – CertainPerformance Nov 26 '20 at 15:18
  • Unfortunately this is not working. Maybe to you it seems easy, but as I am a beginner I cannot debug the code I have very efficiently. For hours I am getting an error: Cannot read property 'length' of undefined. I was hoping there would be someone who can help me as a beginner, but now there is no chance ... – Katharina Schreiber Nov 26 '20 at 17:40

0 Answers0