我们采用了以下项目结构
|- pages
|- <page_name>
|- index.js # To do a default export of the main component
|- MainComponent.jsx # Contains other subcomponents
|- main-component.css # CSS for the main component
|- OtherComponents.jsx # more than 1 file for child components that are used only in that page
|- __tests__ # Jest unit and snapshot tests
|- components
|- index.js # Exports all the default components of each component as named exports
|- CommonCmpnt1
|- CommonCmpnt1.jsx
|- common-cmpnt-1.css
|- index.js …Run Code Online (Sandbox Code Playgroud) 有人可以解释一下 React 中的高阶组件吗?我已经阅读并重新阅读了文档,但似乎无法更好地理解。根据文档,HOC 通过创建一个返回反应组件的主函数,通过将参数传递给该函数来帮助消除重复。我有几个问题。
Button或EnhancedButton。我尝试创建一个这样的 HOC:
// createSetup.js
import React from 'react';
export default function createSetup(options) {
return class extends React.Component {
constructor(props) {
super(props);
this.state = {};
this.testFunction = this.testFunction.bind(this);
}
testFunction() {
console.log("This is a test function");
}
render() {
return <p>{options.name}</p>
}
}
}
// main.js
import React from 'react';
import {render} from 'react-dom';
import createSetup from './createSetup';
render((<div>{() => createSetup({name: 'name'})}</div>),
document.getElementById('root'););
Run Code Online (Sandbox Code Playgroud)运行这个不会显示 HOC,只显示 div
任何人都可以提供比给出的更好的例子吗?
任何人都可以为我正确解释这个表达......这似乎是我目前面临的问题。
开始侦听给定的源 LiveData,当源值更改时将调用 onChanged 观察者。
onChanged只有当此 MediatorLiveData 处于活动状态时才会调用回调。如果给定的 LiveData 已作为源添加但具有不同的观察者,
IllegalArgumentException则将抛出。
我目前有以下作为我的 ViewModel (Called SplashViewModel)
package com.testapp.testapp.ui.splash;
import com.testapp.testapp.repository.HealthTipRepository;
import javax.inject.Inject;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MediatorLiveData;
import androidx.lifecycle.ViewModel;
public class SplashViewModel extends ViewModel {
private final HealthTipRepository healthTipRepository;
// Load Status will be used to fill up the progress bar inside the Activity
private final MediatorLiveData<Integer> loadStatus = new MediatorLiveData<>();
@Inject
SplashViewModel(HealthTipRepository healthTipRepository) {
this.healthTipRepository = healthTipRepository;
}
LiveData<Integer> observeLoadStatus() {
loadStatus.addSource(healthTipRepository.createHealthTips(), healthTips -> {
int …Run Code Online (Sandbox Code Playgroud) java android mvvm android-livedata android-architecture-components
我们在 Nodemailer 中使用我们的 Gmail 凭据发送开发中的测试电子邮件。我们今天尝试使用与昨天相同的配置发送一个并收到以下错误:
2020-05-04T10:17:35.547Z Error: Invalid login: 535-5.7.8 Username and Password not accepted. Learn more at
04/05/2020 12:17:35 535 5.7.8 https://support.google.com/mail/?p=BadCredentials s18sm19281474wra.94 - gsmtp
04/05/2020 12:17:35 at SMTPConnection._formatError (/home/node/backend/node_modules/nodemailer/lib/smtp-connection/index.js:784:19)
04/05/2020 12:17:35 at SMTPConnection._actionAUTHComplete (/home/node/backend/node_modules/nodemailer/lib/smtp-connection/index.js:1523:34)
04/05/2020 12:17:35 at SMTPConnection.<anonymous> (/home/node/backend/node_modules/nodemailer/lib/smtp-connection/index.js:550:26)
04/05/2020 12:17:35 at SMTPConnection._processResponse (/home/node/backend/node_modules/nodemailer/lib/smtp-connection/index.js:942:20)
04/05/2020 12:17:35 at SMTPConnection._onData (/home/node/backend/node_modules/nodemailer/lib/smtp-connection/index.js:749:14)
04/05/2020 12:17:35 at TLSSocket.SMTPConnection._onSocketData (/home/node/backend/node_modules/nodemailer/lib/smtp-connection/index.js:195:44)
04/05/2020 12:17:35 at TLSSocket.emit (events.js:310:20)
04/05/2020 12:17:35 at addChunk (_stream_readable.js:286:12)
04/05/2020 12:17:35 at readableAddChunk (_stream_readable.js:268:9)
04/05/2020 12:17:35 at TLSSocket.Readable.push (_stream_readable.js:209:10)
04/05/2020 12:17:35 2020-05-04T10:17:34.439Z RES …Run Code Online (Sandbox Code Playgroud) javascript ×2
reactjs ×2
android ×1
android-architecture-components ×1
ecmascript-6 ×1
email ×1
gmail ×1
java ×1
mvvm ×1
next.js ×1
node.js ×1
nodemailer ×1
smtp ×1