小编joh*_*ges的帖子

如何在React中更新父状态?

我的结构如下:

Component 1  

 - |- Component 2


 - - |- Component 4


 - - -  |- Component 5  

Component 3
Run Code Online (Sandbox Code Playgroud)

组件3应该根据组件5的状态显示一些数据.由于props是不可变的,我不能简单地将它保存在组件1中并转发它,对吧?是的,我读过有关redux的内容,但不想使用它.我希望只有反应就可以解决它.我错了吗?

javascript web-deployment reactjs

298
推荐指数
12
解决办法
22万
查看次数

如何取消componentWillUnmount上的提取

我认为标题说明了一切.每次卸载仍在提取的组件时都会显示黄色警告.

警告:无法在卸载的组件上调用setState(或forceUpdate).这是一个无操作,但是......要修复,取消componentWillUnmount方法中的所有订阅和异步任务.

  constructor(props){
    super(props);
    this.state = {
      isLoading: true,
      dataSource: [{
        name: 'loading...',
        id: 'loading',
      }]
    }
  }

  componentDidMount(){
    return fetch('LINK HERE')
      .then((response) => response.json())
      .then((responseJson) => {
        this.setState({
          isLoading: false,
          dataSource: responseJson,
        }, function(){
        });
      })
      .catch((error) =>{
        console.error(error);
      });
  }
Run Code Online (Sandbox Code Playgroud)

reactjs

73
推荐指数
4
解决办法
4万
查看次数

如何在 React Native 中解析 HTML 文件?

如何从文件系统获取 HTML 文件并从中解析特定元素。

例如,给定下面的 html 片段,我如何提取表格内容并呈现它?

<html>
<div>
  <h1>header</h1>
  <table id="a" border="1">
    <th>Number</th>
    <th>content A</th>
    <th>contetn A</th>
    <th>content A</th>
    <tr>
      <td>1</td>
      <td>a</td>
      <td>a</td>
      <td>a</td>
    </tr>
    <th>Number</th>
    <th>content B</th>
    <th>content B</th>
    <th>content B</th>

    <tr>
      <td>1</td>
      <td>b</td>
      <td>b</td>
      <td>b</td>
    </tr>
  </table>
</div>
<br>
<footer>footer</footer>

</html>
Run Code Online (Sandbox Code Playgroud)

html javascript html-parsing react-native

8
推荐指数
3
解决办法
2万
查看次数

iOS 14.4 上使用 WKWebView 的 getUserMedia 仍然会产生 NotAllowedError

我正在尝试在 iOS 14.4 上将 getUserMedia 与 Cordova 应用程序中的 WKWebView 一起使用。我正在使用 Cordova 的 HelloWorld 应用程序来重现这一点。

我提供了 NSCameraUsageDescription 字符串。

我正在使用https://webkit.org/blog/11353/mediarecorder-api/上提供的示例代码(但音频设置为 false)。

当我第一次启动应用程序并单击按钮启动流时,会出现权限请求,我对此进行了确认。然后出现此错误:“NotAllowedError:当前上下文中的用户代理或平台不允许该请求,可能是因为用户拒绝了权限”

之后,只有在我重新安装整个应用程序后,权限请求才会再次出现。

我做错了什么吗?据我了解,getUserMedia 应该在 iOS 14.4 中适用于基于 WKWebView 的应用程序,对吗?

ios cordova getusermedia

7
推荐指数
1
解决办法
3645
查看次数

具有异步初始化的单例

我有一个用例,其中 Singleton 对象将异步步骤作为其初始化的一部分。此单例的其他公共方法取决于初始化步骤设置的实例变量。我将如何进行异步调用同步?

var mySingleton = (function () {

  var instance;

  function init() {

    // Private methods and variables
    function privateMethod(){
      console.log( "I am private" );
    }

    var privateAsync = (function(){
      // async call which returns an object
    })();

    return {

      // Public methods and variables

      publicMethod: function () {
        console.log( "The public can see me!" );
      },

      publicProperty: "I am also public",

      getPrivateValue: function() {
        return privateAsync;
      }
    };
  };

  return {

    // Get the Singleton instance if one …
Run Code Online (Sandbox Code Playgroud)

javascript singleton promise

6
推荐指数
1
解决办法
4597
查看次数

Reactjs - 使用子组件中的setState从props设置State

我有以下类根据排序下拉列表呈现用户.如果我选择"按字母顺序",则按字母顺序列出用户,当我选择"组"时,将按组顺序列出.

render(){
    return(
        const {members, sort} = this.state
        { sort === "alphabetical" && <SortByAlphabet members={members} /> }
        { sort === "group" && <SortByGroup members={members}/> }
    )
)
Run Code Online (Sandbox Code Playgroud)

<SortByAlphabet />组件中,我在componentWillReceiveProps()函数中从props.members设置组件状态对象.

componentWillReceiveProps = props => {
    this.setState({ members : props.members });
}
Run Code Online (Sandbox Code Playgroud)

当我选择"组"排序时,<SortByAlphabet />组件将被卸载并<SortByGroup />挂载在DOM中.再次当我切换回"按字母顺序"排序时,在<SortByAlphabet />组件中优先设置的状态变量(成员)变为NULL,因为组件已从DOM中删除.

componentWillReceiveProps函数不会触发第二次重新渲染<SortByAlphabet />b'coz时道具没有改变.但我想更新状态变量,就像我第一次在componentWillReceiveProps功能中做的那样.

怎么做?

javascript reactjs

6
推荐指数
2
解决办法
4487
查看次数

应用程序中心使用 Azure Pipelines 分发 IOS 应用程序:找不到资源

我目前正在使用 Azure Pipelines 使用应用程序中心分发应用程序。

构建并创建certificate.p12和provsion配置文件工作正常,但在App Center Distribute任务中我得到了

Starting: App Center
==============================================================================
Task         : App Center distribute
Description  : Distribute app builds to testers and users via Visual Studio App Center
Version      : 3.173.0
Author       : Microsoft Corporation
Help         : https://learn.microsoft.com/azure/devops/pipelines/tasks/deploy/app-center-distribute
==============================================================================
(node:2022) Warning: Use Cipheriv for counter mode of aes-256-ctr
(node:2022) Warning: Use Cipheriv for counter mode of aes-256-ctr
(node:2022) Warning: Use Cipheriv for counter mode of aes-256-ctr
(node:2022) Warning: Use Cipheriv for counter mode of aes-256-ctr
(node:2022) Warning: Use …
Run Code Online (Sandbox Code Playgroud)

azure-devops visual-studio-app-center

4
推荐指数
1
解决办法
4401
查看次数

电容如何拆卸平台

关于电容器的文档没有提到如何移除平台。

并且删除不存在。

在此处输入图片说明

电容器甚至支持移除平台吗?如何在不明显的情况下删除我的平台 - 手动删除文件夹

capacitor

3
推荐指数
1
解决办法
3683
查看次数